API Call running even if the page close
Unanswered
Scaly-naped Pigeon posted this in #help-forum
Scaly-naped PigeonOP
I want when the user click on a button it keeps running on my server until the process is completed even if the user closed the page , it keeps running the process, what is this called and how can I achieve this?
4 Replies
Toyger
not sure will it work on vercel, but on self-hosted easiest way in route handler you can basically run promise without wait for resolving it.
and then immidiately return response to user.
for user request will be finished, but your promise will be added to microtask queue and will be finished.
and then immidiately return response to user.
for user request will be finished, but your promise will be added to microtask queue and will be finished.
Scaly-naped PigeonOP
so all I need to do is just do a promise without resolve ? but this must be on api routes right ?
@Scaly-naped Pigeon so all I need to do is just do a promise without resolve ? but this must be on api routes right ?
Toyger
yeah, routehandler/api route is easiest way, theoretically you can run it in server action too.
@Toyger yeah, routehandler/api route is easiest way, theoretically you can run it in server action too.
Scaly-naped PigeonOP
thanks for the hint gonna test this out 🙂