Исходники и презентации
This commit is contained in:
18
lessons/contexts/context_with_timeout_cause/main.go
Normal file
18
lessons/contexts/context_with_timeout_cause/main.go
Normal file
@ -0,0 +1,18 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ctx, cancel := context.WithTimeoutCause(context.Background(), time.Second, errors.New("timeout"))
|
||||
defer cancel() // show difference
|
||||
|
||||
<-ctx.Done()
|
||||
|
||||
fmt.Println(ctx.Err())
|
||||
fmt.Println(context.Cause(ctx))
|
||||
}
|
||||
Reference in New Issue
Block a user