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
bascially .waitUntil but for DOs
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
but it blocks the response to the client though
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
It shouldn't, if you don't await it.
I though the output gate would block it… and it still will complete in the background before sleeping a do?
the output gate only blocks waiting for storage writes to hit disk; it doesn't wait for network requests
Awesome, but any running promises will resolve before the DO gets potentially unloaded?
Well exit not necessarily resolve
(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
but it can be longer if the promise is still running?
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)
I'm thining more in the scenario where I do like:
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 responsethe 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.
gotcha, thanks for clarifying
it's the same with
waitUntil()
BTW -- it has a 30-second limit