You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
380 B
Go
18 lines
380 B
Go
2 years ago
|
package contexthelper
|
||
|
|
||
|
import "context"
|
||
|
|
||
|
// WithNoCancel 阻断上级 ctx 的中断信号
|
||
|
// 想要使用上级 ctx 中的值但不想受上级 ctx 控制退出时可以使用
|
||
|
func WithNoCancel(ctx context.Context) context.Context {
|
||
|
return &noCancelCtx{Context: ctx}
|
||
|
}
|
||
|
|
||
|
type noCancelCtx struct {
|
||
|
context.Context
|
||
|
}
|
||
|
|
||
|
func (ctx *noCancelCtx) Done() <-chan struct{} {
|
||
|
return nil
|
||
|
}
|