hono icon indicating copy to clipboard operation
hono copied to clipboard

executionCtx getter throws on Bun

Open comunidadio opened this issue 9 months ago • 3 comments

What version of Hono are you using?

4.3.3

What runtime/platform is your app running on?

Bun

What steps can reproduce the bug?

I want to use executionCtx.waitUntil on CloudFlare Workers, but ignore and just await when running on Bun (since waitUntil is unsupported by Bun.serve)

app.get('/example', async (c) => {
    const p = getSomePromise();
    if (c.executionCtx) {
       c.executionCtx.waitUntil(p);
    } else {
        await p;
    }
    return c.text("OK!")
})

However this crashes at the "if (c.executionCtx)" guard because executionCtx is a getter function that throws when it's not available.

Shouldn't this return undefined or null instead of throwing to allow for the use case above?

What is the expected behavior?

Do not throw.

What do you see instead?

error: This context has no ExecutionContext as per https://github.com/honojs/hono/blob/aebaa2846228eea30a1787cde01a3d2e25fc803f/src/context.ts#L183

Additional information

No response

comunidadio avatar May 09 '24 08:05 comunidadio