Support for context.Context
It would be good if the API can support ctx context.Context to cancel builds.
The API for canceling a build is here: https://esbuild.github.io/api/#cancel
@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 {
}
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
See: https://github.com/romance-dev/go-bundler/blob/main/bundler.go#L139 (unlicensed for the time being)