IIRC there is no way to launch a promise

IIRC there is no way to launch a promise in a durable object (from a request) in such a way that does not block a response? For example I am trying to ship logs from a custom logger async to loki, but i don't want that to block responding to a request
15 Replies
DanTheGoodman
DanTheGoodmanOP16mo ago
bascially .waitUntil but for DOs
sathoro
sathoro16mo ago
I think if you just call the promise and don't await it, it will still get processed in the background for up to 1 minute
DanTheGoodman
DanTheGoodmanOP16mo ago
but it blocks the response to the client though
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
kenton
kenton16mo ago
It shouldn't, if you don't await it.
DanTheGoodman
DanTheGoodmanOP16mo ago
I though the output gate would block it… and it still will complete in the background before sleeping a do?
kenton
kenton16mo ago
the output gate only blocks waiting for storage writes to hit disk; it doesn't wait for network requests
DanTheGoodman
DanTheGoodmanOP16mo ago
Awesome, but any running promises will resolve before the DO gets potentially unloaded? Well exit not necessarily resolve
kenton
kenton16mo ago
(and FWIW the output gate will actually block both responses and outgoing fetch()es, until all writes are durable) The DO will will wait at least 30 seconds (actually 70 seconds) for remaining I/O after the last client disconnects essentially it automatically does waitUntil which is why we removed the explicit waitUntil API
DanTheGoodman
DanTheGoodmanOP16mo ago
but it can be longer if the promise is still running?
kenton
kenton16mo ago
if there is still a client waiting for a response, the DO will not be evicted at all (well, unless hibernation is enabled for that request/response)
DanTheGoodman
DanTheGoodmanOP16mo ago
I'm thining more in the scenario where I do like:
storage.put()
sendLogsToLoki() // promise
return new Response()
storage.put()
sendLogsToLoki() // promise
return new Response()
where the sendLogsToLoki is a promise that does not block the client getting a response, but the DO wont unload until that promise resolves so in theory the client could be disconnected already while that promise is still running due to retries or what ever I think that's safe based on what's explained above? And that the sendLogsToLoki promise wont block the client from getting the response
kenton
kenton16mo ago
the DO will be evicted some time after the last client disconnects, even if there are outgoing requests still in flight. Those requests will be canceled.
DanTheGoodman
DanTheGoodmanOP16mo ago
gotcha, thanks for clarifying
kenton
kenton16mo ago
it's the same with waitUntil() BTW -- it has a 30-second limit
Want results from more Discord servers?
Add your server