Depends on how quickly you want the expensive operation to terminate. Unless it
is cpu bound the expensive operation probably is making IO calls - pass the
context to those so the cancel will propagate. If it doesn’t I think a periodic
poll/check of the context is simpler.
> On Jan 8, 2021, at
> On 8 Jan 2021, at 1:59 pm, Robert Engels wrote:
>
> You need to pass the context to the expensive work a periodically check if it
> has been cancelled.
Thanks. I was thinking how to implement this. Is this a nice way to do it?
func clientDisconnected(ctx context.Context, done chan bool)
You need to pass the context to the expensive work a periodically check if it
has been cancelled.
> On Jan 7, 2021, at 8:55 PM, Amit Saha wrote:
>
> Hi all, I want to confirm whether my understanding related to handling
> HTTP client disconnections is correct or not.
>
> Consider this:
>
>
Hi all, I want to confirm whether my understanding related to handling
HTTP client disconnections is correct or not.
Consider this:
func longRunningProcessing(ctx context.Context, w http.ResponseWriter) {
done := make(chan bool)
go func() {
expensiveWork() # This is a blocking exp