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

    Subh

    08/26/2021, 9:31 AM
    Great insight @User thank you so much
  • r

    raRaRa

    08/26/2021, 4:38 PM
    Hmm, am I not able to clearInterval a timer? The error I get from the DO is: Cannot clear a timeout created in a different request context.
  • r

    raRaRa

    08/26/2021, 4:39 PM
    Really odd
  • v

    Vanessa🦩

    08/26/2021, 4:42 PM
    Yep. You have to emulate Intervals with repeated
    setTimeouts
    . You can't clear those either but you can gate them. I made a little helper for that: https://gist.github.com/codefrau/cd7d25ee88f034c71bba9cf6ba51f9b7
  • v

    Vanessa🦩

    08/26/2021, 4:44 PM
    ... and I sure hope this will be fixed before GA 😅 I reported it back in May https://discord.com/channels/595317990191398933/773219443911819284/847724822984261633
  • r

    raRaRa

    08/26/2021, 4:44 PM
    Hmm I see, do you know why this is happening though? Is it because the timer was created in context from another user
  • v

    Vanessa🦩

    08/26/2021, 4:47 PM
    I think for some reason DOs still retain the idea that resources should be separated by request. That makes sense for regular worker requests but not for DOs, because the whole point of a DO is to serve many requests.
  • r

    raRaRa

    08/26/2021, 4:47 PM
    Yeah that makes sense, and hopefully it'll be fixed 🙂
  • r

    raRaRa

    08/26/2021, 4:48 PM
    I'm running game session logic with setTimeouts, e.g. how long someone can draw per round
  • v

    Vanessa🦩

    08/26/2021, 4:48 PM
    It's just a bug, but likely deep down in the architecture. @User ? @User ? Any news?
  • r

    raRaRa

    08/26/2021, 4:49 PM
    Your fix seems nice, so you basically cancel the timeout so it doesn't fire the callback function if it's cancelled.
  • v

    Vanessa🦩

    08/26/2021, 4:50 PM
    Right. Pretty straightforward. And once Cloudflare fixes the 10,000 timeout limit it can easily be used to implement intervals. (I have not checked that one lately)
  • r

    raRaRa

    08/26/2021, 4:51 PM
    Yeah, thank you so much for the fix and quick response! 🙂
  • k

    kenton

    08/26/2021, 4:52 PM
    there is a fix in the works, just held up in code reviews which is mostly my fault (as the overly-strict reviewer)
  • v

    Vanessa🦩

    08/26/2021, 4:53 PM
    Both for the "cannot clear" error and "too many timeouts" ?
  • r

    raRaRa

    08/26/2021, 5:05 PM
    @User is there any problem with your fix if I use a global var for the timer? E.g. this.roundTimer = setTimeout(...) and then later in another user context the timer might get replaced with a new one.
  • r

    raRaRa

    08/26/2021, 5:06 PM
    So basically in my pictionary, if someone finds the correct word, the round timer is changed to 20 seconds, from whatever it was before 🙂
  • r

    raRaRa

    08/26/2021, 5:06 PM
    Of course I clear it before replacing: if (this.roundTimer) { clearTimeout(this.roundTimer) } this.roundTimer = setTimeout(() => { this.endRound() }, 10000)
  • v

    Vanessa🦩

    08/26/2021, 5:06 PM
    you shouldn't be using globals because global state is sometimes shared between DO instances.
  • r

    raRaRa

    08/26/2021, 5:07 PM
    Ah hmm by global I mean (this) as in the reference inside the DO
  • r

    raRaRa

    08/26/2021, 5:07 PM
    (this) within the class
  • v

    Vanessa🦩

    08/26/2021, 5:07 PM
    oh yes that is fine, that is how I use it
  • r

    raRaRa

    08/26/2021, 5:07 PM
    Ok great!
  • r

    raRaRa

    08/26/2021, 7:41 PM
    Is there a way to dispose/kill a DO instance?
  • r

    raRaRa

    08/26/2021, 7:41 PM
    E.g. if everyone leaves a room
  • w

    Walshy | Pages

    08/26/2021, 7:44 PM
    if you delete everything from the DO then it will be cleaned up and removed
  • a

    albert

    08/26/2021, 7:52 PM
    Does
    {cf: {cacheTtl: 3600}}
    work on requests to durable objects?
  • r

    raRaRa

    08/27/2021, 11:45 AM
    Is there a limit on how large a websocket message can be?
  • r

    raRaRa

    08/27/2021, 11:46 AM
    And can I guarantee that websocket messages sent from DO to user are received in same order
  • b

    brett

    08/27/2021, 1:32 PM
    No, the cache isn't between a normal Worker and a Durable Object like it is between a normal Worker and origin. You'd need to make a client side wrapper around your DO fetches that uses the Cache API and fell back to fetching from the DO
1...166167168...567Latest