Исходники и презентации
This commit is contained in:
18
lessons/contexts/with_ctx_check/main.go
Normal file
18
lessons/contexts/with_ctx_check/main.go
Normal file
@ -0,0 +1,18 @@
|
||||
package main
|
||||
|
||||
import "context"
|
||||
|
||||
func WithContexCheck(ctx context.Context, action func()) {
|
||||
if action == nil || ctx.Err() != nil {
|
||||
return
|
||||
}
|
||||
|
||||
action()
|
||||
}
|
||||
|
||||
func main() {
|
||||
ctx := context.Background()
|
||||
WithContexCheck(ctx, func() {
|
||||
// do something
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user