Skip to content
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

Nested waitUntil not awaited #605

Closed
hansottowirtz opened this issue Jun 14, 2023 · 0 comments · Fixed by #606
Closed

Nested waitUntil not awaited #605

hansottowirtz opened this issue Jun 14, 2023 · 0 comments · Fixed by #606

Comments

@hansottowirtz
Copy link
Contributor

When calling waitUntil inside another waitUntil, the nested waitUntil should also be awaited. This does not happen in Miniflare v2.

Minimal repro:

import { Miniflare } from "miniflare";

const mf = new Miniflare({
  script: `
  const delay = (n) => new Promise((res) => setTimeout(res, n))

  export default {
    async fetch(req, env, ctx) {
      const fn = async () => {
        await delay(2000);

        ctx.waitUntil(delay(2000).then(()=>{
          console.log("nested waitUntil promise resolved")
        }))

        console.log("fn resolved")
      };

      ctx.waitUntil(fn())

      return new Response("ok", { status: 200 })
    }
  }`,
  modules: true,
  compatibilityDate: "2023-03-30"
});


const res = await mf.dispatchFetch("https://test", { method: "GET" });
console.log("received response")
await res.waitUntil()
console.log("wait until done")

nested waitUntil promise resolved is never logged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant