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

    DanTheGoodman

    02/26/2023, 10:15 PM
    Yeah I meant more the input/output gates thing
  • c

    crabmusket

    02/26/2023, 11:28 PM
    Do you have any plans to write about patterns for dealing with websockets? E.g. maintaining connection state, what sorts of error/failure situations to handle (this is the big unknown for me)?
  • l

    Larry

    02/27/2023, 1:17 AM
    Sorry, I'm exploring pub-sub with the websocket javascript client rather than durable object's websocket support because I eventually need pub-sub functionality anyway.
  • j

    johtso

    02/27/2023, 2:23 AM
    I was also leaning in that direction
  • c

    crabmusket

    02/27/2023, 3:56 AM
    Ok, maybe once I've done some experiments I'll reach out and see if you're interested in a guest post 😉
  • b

    bkyerv

    02/27/2023, 12:27 PM
    why did you choose medium? asking out of curiosity. and of course huge thanks for starting to write more on DO
  • l

    Larry

    02/27/2023, 12:54 PM
    I definitely want guest posts!
  • l

    Larry

    02/27/2023, 12:55 PM
    Not a conscious decision. I have posted there before.
  • c

    ckoeninger

    02/27/2023, 4:49 PM
    No plans, what would your use case be?
  • w

    Wallslide

    02/27/2023, 6:45 PM
    Transactional storage's put and delete functions support up to 128 keys at a time. But what if I loop over them without using await over 128 times (taking advantage of automatic write coalescing). Is that going to run into the same limit? Do I need to await at least once every 128 operations?
  • c

    ckoeninger

    02/27/2023, 10:36 PM
    see "Write buffer behavior" under https://developers.cloudflare.com/workers/runtime-apis/durable-objects/#transactional-storage-api not a 128 key limit per se, but if you're doing enough writes that memory is a concern you'll want to await
  • z

    zehawk

    02/28/2023, 9:12 AM
    To separate creation vs usage - have privileged access via the CF APIs from the backend for creation, while not allowing such a path for normal usage operation via the worker.
  • s

    Subh

    02/28/2023, 10:15 AM
    I have two
    durable_objects
    bindings as
    User
    and
    Group
    . Is there a way to index or filter to get all the User in a Group without putting them in
    Group
    object?
    Copy code
    export class Group implements DurableObject {
    state: DurableObjectState;
    app: Hono = new Hono();
    users: Record<string, User> = {};
  • c

    ckoeninger

    02/28/2023, 6:57 PM
    if you want a Group object to know about User objects, you'll have to put that info in. The only indexing built in to Durable objects is by name/id for the object, then by key for storage within that object
  • s

    Subh

    02/28/2023, 7:16 PM
    Hmm, right. So let’s say I add the groupId in the User object. How do I fetch all the user using the groupid ? Is there an example I can follow or I can read about?
  • s

    Subh

    02/28/2023, 7:18 PM
    I am playing around with key. ${groupId}:${userId}
  • c

    ckoeninger

    02/28/2023, 7:44 PM
    you'll have to write data the way you want to query it. So if given a group you want to know all users in that group, and you have a DO named for the group, you'd want to store users in that DO for the group. If it's not a lot of users, you may be able to just stick them in an array under a storage key named e.g. "users". If it's potentially a lot of users, store under a key per user with some naming convention (e.g. keys starting with "user") that allows you to use state.storage.list with appropriate start / end / limit parameters
  • s

    Subh

    03/01/2023, 11:54 AM
    Gotcha! Helped a lot. One last thing, Lets say I have
    User
    object
    Copy code
    export class User implements DurableObject {
    state: DurableObjectState;
    data: {}
    }
    I could store data like so
    Copy code
    await this.state.storage?.put("userData", {        ...userData,      });
    or
    Copy code
    this.data = userData;
    When to use which one? advantages and disadvantages?
  • s

    Skye

    03/01/2023, 11:56 AM
    If you use
    this.data = userData
    , you won't get the persistence of putting it in storage
  • s

    Skye

    03/01/2023, 11:57 AM
    I.e. when the DO ends, it's evicted
  • s

    Subh

    03/01/2023, 12:05 PM
    what do you mean by
    DO ends
    ?
  • s

    Skye

    03/01/2023, 12:07 PM
    When your DO stops processing tasks or requests, after a short period it'll stop running
  • s

    Subh

    03/01/2023, 12:42 PM
    oh right! Got it, thanks 🙂
  • j

    john.spurlock

    03/01/2023, 2:48 PM
    waitUntil
    is technically available as a member of the first arg to the DO constructor https://developers.cloudflare.com/workers/runtime-apis/durable-objects/#durable-object-class-definition but as mentioned there and here, it's not really necessary in DOs
  • d

    DanTheGoodman

    03/01/2023, 2:49 PM
    Thanks!
  • a

    alias

    03/02/2023, 3:56 AM
    Hey all, similar to the above convo, I'm trying to use
    this.state.blockConcurrencyWhile
    in a DurableObject constructor to set up instance variables. The docs, and types specify that this should be an available function, however actually calling this function throws an unhandled error
    (node:79350) UnhandledPromiseRejectionWarning: TypeError: this.state.blockConcurrencyWhile is not a function
    . Anyone familiar with this?
  • a

    alias

    03/02/2023, 3:59 AM
    I suspect this might actually be an issue with miniflare
  • h

    HardAtWork

    03/02/2023, 7:06 AM
    Just to make sure, have you assigned this.state to the state passed into the constructor?
  • l

    Larry

    03/02/2023, 2:15 PM
    Won't help you fix this problem but I use a lazy hydration approach that avoids this problem. I've written it up here just now for you: https://medium.com/cloudflare-durable-objects-design-patterns/lazy-hydration-cab27e7c70b5
  • h

    HardAtWork

    03/03/2023, 9:58 PM
    I forget, is there a way to derive the locationHint from an already-created DO?
1...507508509...567Latest