I want to cancel the go-routines invoked by my custom middleware as follows. However, these go-routines are continued to run even after the middleware is no longer in use. Is there any way to cancel the go-routine?
// New created a new Demo plugin.
func New(ctx context.Context, next http.Handler, conf *Config, name string) (http.Handler, error) {
go func() {
for {
select {
case <-ctx.Done():
// ctx should be canceled when the middleware is no longer in use
// in my expectation. However, it is not cancelled.
return
}
}
}()
return &Demo{
next: next,
}, nil
}