workers-sdk icon indicating copy to clipboard operation
workers-sdk copied to clipboard

🚀 Feature Request: a way to only stop `unstable_dev` once all `waitUntil()` promises resolved in test mode

Open cameron-robey opened this issue 3 years ago • 0 comments

Describe the solution

For testing, it would be nice to have a way to only stop unstable dev once all promises in waitUntil()s have been resolved.

For the following script:

addEventListener("fetch", (event) => {
  event.waitUntil(new Promise((resolve) => {
    setTimeout(() => {
      console.log('waited');
      resolve();
    }, 1000);
  }));
  event.respondWith(new Response("Hello world" + String(count)));
});

if we run the following,

const worker = await unstable_dev("index.js", {}, { disableExperimentalWarning: true });

const resp = await worker.fetch();
await worker.stop();

then we the execution gets stopped before the waitUntil promise resolves and hence we never get the console.log output.

The solution would be a way to await all waitUntil() promises resolving.

cameron-robey avatar Sep 09 '22 13:09 cameron-robey