-
Notifications
You must be signed in to change notification settings - Fork 554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support deferred functions with waitUntil
#1705
Comments
Hi. I think what you are looking for is You can also access to the pending promises with See this example: https://stackblitz.com/edit/github-ch89s7?file=routes%2Findex.ts,plugins%2Fbackground.ts Let me know if this is what you think and resolves your problem or if have any idea to improve API. |
If I'm not mistaken it looks like you are implementing a very basic queue pattern ? I would love if we could support queues as a first class citizen (similar to laravel); in the meantime there's this cloudflare hook based approach we've been tinkering with https://github.com/unjs/nitro/pull/1579/files |
waitUntil does in fact do what I want. I get that it's called I'm not seeing where these waitUntil promises are resolved? Where do I find that? I'm interested in seeing if they are resolved after each other or with Promise.all. Also, is this called when the request is done for the user or when the server closes? (I don't know enough, but maybe the server won't close if there's another ongoing request?) I'm not too familiar with Cloudflare, but I'm definitely not thinking of queues in the sense that there is a worker process that handles jobs. I'm thinking staying within the request lifecycle. |
Also, would adding the |
Can the waitUntil be updated so it can take regular functions too? Maybe some people want to do some more heavy computation that is in sync, but the user doesn't have to wait for it. |
waitUntil
Thanks for the feedbacks. The initial API was designed following up cloudflare workers. They expect you to give the util a promise that is already running in parallel to the request. I think we can as well allow passing functions to |
what are your thoughts on the |
Since we already introduced (platform agnostic) You can also use Re |
waitUntil
waitUntil
Describe the feature
I have an endpoint I don't want the user to wait while I talk to third party apis that isn't critical to the response So such logic could be run after the response has been sent.
For example:
Then the runAfterResponse looks like this:
getRequestFingerprint in turn looks like:
(the getRequestFingerprint could be a Pull Request on its own...
And lastly I have a nitro plugin that will process these callbacks
Let me know your thoughts, concerns, etc.
I have tested this and it works as expected with with the order of execution
console.log(new Date().getSeconds(), {count})
Additional information
The text was updated successfully, but these errors were encountered: