https://discord.cloudflare.com logo
Join Discord
Powered by
# durable-objects
  • k

    kenton

    02/09/2021, 12:18 AM
    The intent is that you'll be able to export multiple "entrypoints" to your worker under various names. So like you could have different routes on your zone use different entrypoints, for example. The "default" entrypoint is, well, the default, if you haven't chosen a named one.
  • k

    kenton

    02/09/2021, 12:18 AM
    at some point workers will be able to call other workers, and you could have a private entrypoint which is only exposed to some other worker, not to the public internet
  • j

    jed

    02/09/2021, 12:19 AM
    ah, i see.
  • j

    jed

    02/09/2021, 12:19 AM
    then i guess it's kinda weird that the default export is an object, but the named exports are constructors.
  • k

    kenton

    02/09/2021, 12:20 AM
    they are only constructors if they are implementing Durable Objects
  • k

    kenton

    02/09/2021, 12:20 AM
    named non-DO entrypoints would be objects with methods like
    fetch
  • j

    jed

    02/09/2021, 12:21 AM
    ah, i get it.
  • j

    jed

    02/09/2021, 12:23 AM
    (personally i'd prefer a similar API since whether my worker is a DO or not is a bit of an implementation detail... similarly as how i'd like the KV and DO storage API to be closer).
  • j

    jed

    02/09/2021, 12:23 AM
    but i see the distinction.
  • j

    jed

    02/09/2021, 12:23 AM
    🙇
  • k

    kenton

    02/09/2021, 12:24 AM
    hmm, well, with durable objects you need somewhere to hang your in-memory state...
  • k

    kenton

    02/09/2021, 12:24 AM
    instantiating a class gives you a place for that
  • j

    jed

    02/09/2021, 12:25 AM
    (personally i prefer closures for that, but it's just a personal preference. feels like the same reason that react et al are moving away from classes as an API)
  • k

    kenton

    02/09/2021, 12:26 AM
    hmm, how would that work?
  • k

    kenton

    02/09/2021, 12:26 AM
    not sure I understand what you mean
  • j

    jed

    02/09/2021, 12:26 AM
    export default state => async (request, env) => { ... }
  • j

    jed

    02/09/2021, 12:27 AM
    (but this is when there's just
    fetch
    , obviously)
  • k

    kenton

    02/09/2021, 12:28 AM
    I see, so the signature of DO entrypoints would still be different, in that the handlers would expect to receive a
    state
    first
  • k

    kenton

    02/09/2021, 12:28 AM
    in a curried fashion
  • j

    jed

    02/09/2021, 12:28 AM
    yeah.
  • j

    jed

    02/09/2021, 12:28 AM
    same for
    env
    , to be honest
  • j

    jed

    02/09/2021, 12:28 AM
    it feels weird that it's on the request.
  • j

    jed

    02/09/2021, 12:29 AM
    because it should be static for the life of the worker, no?
  • k

    kenton

    02/09/2021, 12:29 AM
    sort of. We have found some use cases where we really want to be able to vary parts of
    env
    per-request.
  • k

    kenton

    02/09/2021, 12:29 AM
    (mostly internal use cases)
  • k

    kenton

    02/09/2021, 12:30 AM
    but for durable objects,
    env
    is delivered to the constructor
  • k

    kenton

    02/09/2021, 12:30 AM
    so not per-request
  • k

    kenton

    02/09/2021, 12:30 AM
    so yeah, it would make sense to have
    (state, env) => (request) => { ... }
  • j

    jed

    02/09/2021, 12:30 AM
    hmmm. for me it's a bit annoying because i have for example AWS keys, and i need to instantiate aws4fetch every call instead of once.
  • g

    Greg Brimble | Cloudflare Pages

    02/09/2021, 12:31 AM
    Just my 2c purely on the naming: a class instance makes more sense in my head as a "Durable Object" than curried functions.
1...131415...567Latest