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

executionCtx getter throws on Bun #2649

Open
comunidadio opened this issue May 9, 2024 · 1 comment
Open

executionCtx getter throws on Bun #2649

comunidadio opened this issue May 9, 2024 · 1 comment

Comments

@comunidadio
Copy link

comunidadio commented May 9, 2024

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

throw Error('This context has no ExecutionContext')

Additional information

No response

@comunidadio comunidadio added the bug label May 9, 2024
@yusukebe yusukebe removed the bug label May 14, 2024
@yusukebe
Copy link
Member

Hi @comunidadio !

Thank you for creating the issue. It's not a bug, but we may have to consider whether it should throw the error or not. As you said, it's convenient that it returns undefined.

It may not be the best solution, but you can use getRuntimeKey() to detect the runtime and make it do the c.executionCxt only in the workerd case.

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

But I think it should not have to look at the runtime key for that purpose. We should consider it.

@usualoma What do you think about this?

Anyway, if we change the behavior, it will be a breaking change that will be included in the next major release.

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

No branches or pull requests

2 participants