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

    Greylock

    06/28/2021, 5:02 PM
    yeah if you make it unbound/unbundled
  • v

    vans163

    06/28/2021, 5:24 PM
    How to do that?
  • v

    vans163

    06/28/2021, 5:26 PM
    What is globalThis? Is that some DO magic constant?
  • d

    Deebster

    06/28/2021, 5:46 PM
    It's not a Cloudflare thing: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
  • v

    vans163

    06/28/2021, 5:47 PM
    Wow thankyou
  • v

    vans163

    06/28/2021, 5:48 PM
    Would using globalThis remove the execution limit of the timer?
  • d

    Deebster

    06/28/2021, 5:48 PM
    no, it's only needed in Vanessa's code because we've got a local alias for setTimeout so it's a way to call the original
  • v

    vans163

    06/28/2021, 5:48 PM
    1 problem I had using timers was if the timer called another settimeout, eventually it will die
  • d

    Deebster

    06/28/2021, 5:50 PM
    that code is a shim to change set/clearTimeout to still timeout but with a NOP - this is to get around a bug with the CF env
  • v

    vans163

    06/28/2021, 5:50 PM
    say if I have a DO with constantly >1 connected websockets. if any of those requests into the DO set off a setTimeout, then that setTimeout operates in singleshot mode, eventually it will die
  • v

    vans163

    06/28/2021, 5:51 PM
    but I want it to keep ticking as it detects if a client become a zombie socket
  • d

    Deebster

    06/28/2021, 5:51 PM
    it sounds pretty similar to what I'm doing. If you're setting a new timeout in your timeout handler, you don't need to worry about it dying (for that reason, anyway)
  • d

    Deebster

    06/28/2021, 5:53 PM
    You probably want to use the persistent storage anyway, as DOs might die for other reasons (error, hardware failure, CF moving your DO). Depends on your project, of course
  • v

    vans163

    06/28/2021, 5:53 PM
    for me if i set new timeout (inside original timeout) it still expired eventually (and the DO did not restart). but i did not use globalThis, are you using globalThis?
  • d

    Deebster

    06/28/2021, 5:54 PM
    I wasn't previously, but it should be the same function, it's just a more qualified path to it
  • v

    vans163

    06/28/2021, 5:54 PM
    ignore that
  • d

    Deebster

    06/28/2021, 5:55 PM
    my timeouts are zombie checks and game timers. I'm not finding the DO can die when websockets are connected, no matter what the timers are doing
  • v

    vans163

    06/28/2021, 5:55 PM
    i have it like
  • v

    vans163

    06/28/2021, 5:55 PM
  • v

    vans163

    06/28/2021, 5:56 PM
    and do_tick checks if this.ticking == false -> setTimeout, else ignore
  • v

    vans163

    06/28/2021, 5:56 PM
    so the first request to spin up the DO starts the tick
  • v

    vans163

    06/28/2021, 5:57 PM
    depending how many clients are connected, eventually this tick dies
  • v

    vans163

    06/28/2021, 5:57 PM
    the moreclients the faster it dies
  • d

    Deebster

    06/28/2021, 5:58 PM
    Do you know about the 10,000 limit on setTimeouts?
  • d

    Deebster

    06/28/2021, 5:59 PM
    You're hitting that limit if you see the error
    You have exceeded the number of timeouts you may set
  • v

    vans163

    06/28/2021, 5:59 PM
    no what is this limit
  • v

    vans163

    06/28/2021, 5:59 PM
    how to avoid it?
  • v

    vans163

    06/28/2021, 5:59 PM
    use setInterval?
  • v

    vans163

    06/28/2021, 6:00 PM
    i was using setTimeout as a oneshot loop, i could use setInterval and drop the call if the work is not done yet
  • d

    Deebster

    06/28/2021, 6:02 PM
    Ok, I think this is your problem then. setTimeout and setInterval are limited to 10k per worker. It's from before DOs were a thing. Good news: they're working on fixing it. Bad news: no workaround atm (that I know of, anyway)
1...109110111...567Latest