Skip to content

Instantly share code, notes, and snippets.

@ostretsov
Created July 22, 2023 03:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ostretsov/e3b4e0ab5dc79de7d5a1363ef90a7293 to your computer and use it in GitHub Desktop.
Save ostretsov/e3b4e0ab5dc79de7d5a1363ef90a7293 to your computer and use it in GitHub Desktop.
package main
import (
"context"
"fmt"
"time"
)
func Example_fnDoesntRespectContext() {
fn := func(ctx context.Context) {
time.Sleep(100 * time.Millisecond)
fmt.Println("Плевать на контекст, я все равно работаю")
}
wait := make(chan struct{})
ctx, cancel := context.WithCancel(context.Background())
go func() {
fn(ctx)
close(wait) // signalling the function has finished
}()
cancel() // cancel does not stop the function
<-wait
// Output: Плевать на контекст, я все равно работаю
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment