File tree 1 file changed +11
-3
lines changed
1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change 8
8
// BlockOption define an option function applied to a nursery block.
9
9
type BlockOption func (cfg * nursery )
10
10
11
- // WithContext returns a nursery block option that replace nursery context with
11
+ // WithContext returns a nursery block option that replaces nursery context with
12
12
// the given one.
13
13
func WithContext (ctx context.Context ) BlockOption {
14
14
return func (n * nursery ) {
@@ -20,15 +20,23 @@ func WithContext(ctx context.Context) BlockOption {
20
20
// a new one that timeout after the given duration.
21
21
func WithTimeout (timeout time.Duration ) BlockOption {
22
22
return func (n * nursery ) {
23
- n .Context , n .cancel = context .WithTimeout (n .Context , timeout )
23
+ ctx := n .Context
24
+ if ctx == nil {
25
+ ctx = context .Background ()
26
+ }
27
+ n .Context , n .cancel = context .WithTimeout (ctx , timeout )
24
28
}
25
29
}
26
30
27
31
// WithDeadline returns a nursery block option that wraps nursery context with
28
32
// a new one that will be canceled at `d`.
29
33
func WithDeadline (d time.Time ) BlockOption {
30
34
return func (n * nursery ) {
31
- n .Context , n .cancel = context .WithDeadline (n .Context , d )
35
+ ctx := n .Context
36
+ if ctx == nil {
37
+ ctx = context .Background ()
38
+ }
39
+ n .Context , n .cancel = context .WithDeadline (ctx , d )
32
40
}
33
41
}
34
42
You can’t perform that action at this time.
0 commit comments