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

Support for context.Context #4059

Open
pjebs opened this issue Jan 31, 2025 · 4 comments
Open

Support for context.Context #4059

pjebs opened this issue Jan 31, 2025 · 4 comments

Comments

@pjebs
Copy link

pjebs commented Jan 31, 2025

It would be good if the API can support ctx context.Context to cancel builds.

@evanw
Copy link
Owner

evanw commented Jan 31, 2025

The API for canceling a build is here: https://esbuild.github.io/api/#cancel

@pjebs pjebs closed this as completed Jan 31, 2025
@pjebs pjebs reopened this Jan 31, 2025
@pjebs
Copy link
Author

pjebs commented Jan 31, 2025

@evanw

As per your code in your docs: https://esbuild.github.io/api/#cancel

  ctx, err := api.Context(api.BuildOptions{...})
  if err != nil { <------------------------------Doesn't work in the way of idiomatic Go 
    return err
  }

Maybe api.Context should return a standard untyped error instead of *ContextError (that implements error)?

The workaround doesn't look nice:

ctx, err := api.Context(api.BuildOptions{...})
if err.(*api.ContextError) != nil {

}

@evanw
Copy link
Owner

evanw commented Feb 6, 2025

Sorry, I'm confused. Your first example with err != nil already compiles and works correctly, and your second "workaround" example with err.(*api.ContextError) != nil doesn't compile or work. This is the compile error:

invalid operation: err (variable of type *api.ContextError) is not an interface

@pjebs
Copy link
Author

pjebs commented Feb 6, 2025

See: https://github.com/romance-dev/go-bundler/blob/main/bundler.go#L139 (unlicensed for the time being)

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