Task after returning response

We need to speed up a API running on CF Workers Sites.

Is it possible to return a response quickly and run some slow tasks afterwards as part of the same request?

If not, what’s job queue system is recommended for CF Workers?

You can pass a promise to event.waitUntil(promise) which will let the promise continue to finish after you’ve already returned a response.

I’ve uploaded a small example to https://gist.github.com/arunesh90/3b0fef2c1c77b106b14ebba9ea26321c which you can then plug into https://cloudflareworkers.com/ to see how it works.
In the example you’ll see that the promise that I passed with event.waitUntil() still continues to run after the worker has already returned a response

1 Like

Thank you, @arunesh90!