Исходники и презентации
This commit is contained in:
17
lessons/contexts/chech_cancel/main.go
Normal file
17
lessons/contexts/chech_cancel/main.go
Normal file
@ -0,0 +1,17 @@
|
||||
package main
|
||||
|
||||
import "context"
|
||||
|
||||
func incorrectCheck(ctx context.Context, stream <-chan string) {
|
||||
data := <-stream
|
||||
_ = data
|
||||
}
|
||||
|
||||
func correctCheck(ctx context.Context, stream <-chan string) {
|
||||
select {
|
||||
case data := <-stream:
|
||||
_ = data
|
||||
case <-ctx.Done():
|
||||
return
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user