19 lines
255 B
Go
19 lines
255 B
Go
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
|
|
})
|
|
}
|