Исходники и презентации
This commit is contained in:
17
lessons/contexts/context_without_cancel/main.go
Normal file
17
lessons/contexts/context_without_cancel/main.go
Normal file
@ -0,0 +1,17 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
innerCtx := context.WithoutCancel(ctx)
|
||||
cancel()
|
||||
|
||||
if innerCtx.Err() != nil {
|
||||
fmt.Println("canceled")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user