waitUntil() + setTimeout() How long will waitUntil() wait for?

Say I create this sleep function that waits for a setTimeout to complete before resolving a promise:

function sleep(milliseconds) {
    return new Promise(r=>setTimeout(r, milliseconds));

And I want to use it with waitUntil()? How long will it wait for before it’s too long? Or is there almost no limit? Example code to wait for 86400000 ms (24 hours) then execute function dosomething():


Would 24 hours be too long? What would be too long?

The above was supposed to say event.waitUntil. I tried to fix it immediately after posting it but I kept getting a 403 Forbidden error.

I don’t actually need it to wait 24 hours. I just used that as an example. Worst case scenario I’d need to wait for around 60 seconds.

workUntil will keep the Worker alive for 30 seconds. Not anywhere near a day. I suggest you use cron triggers instead - https://developers.cloudflare.com/workers/platform/cron-triggers/

I need to schedule an event from a worker to take place around 60 seconds after script execution. This is because 60 seconds is the longest length of time it takes to delete a key.

I’m not sure how to use a worker create a temporary cron trigger and execute 60 seconds later. But it sounds like that’s what I’ll have to do.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.