Skip to content

Commit a84ed02

Browse files
committed
work with options without a pointer
1 parent b376185 commit a84ed02

2 files changed

Lines changed: 6 additions & 8 deletions

File tree

closer/closer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func CloseAll() {
6565
func New(ctx context.Context, opts ...Option) (context.Context, *closer) {
6666
o := options{}
6767
for _, opt := range opts {
68-
opt(&o)
68+
o = opt(o)
6969
}
7070

7171
var cancel context.CancelFunc

closer/options.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,22 @@ type options struct {
1111
ctxCancel bool
1212
}
1313

14-
type Option func(*options)
14+
type Option func(options) options
1515

1616
// WithContextCancel allows to call closer CloseAll on context cancel implicitly.
1717
func WithContextCancel() Option {
18-
return func(o *options) {
18+
return func(o options) options {
1919
o.ctxCancel = true
20+
return o
2021
}
2122
}
2223

2324
// WithSignals will trigger creation of signal notifiable context.
2425
// The closer CloseAll will be called implicitly when any of the specified signals arrives.
2526
func WithSignals(signals ...os.Signal) Option {
26-
return func(o *options) {
27+
return func(o options) options {
2728
o.ctxCancel = true
28-
if o.signals == nil {
29-
o.signals = signals
30-
return
31-
}
3229
o.signals = append(o.signals, signals...)
30+
return o
3331
}
3432
}

0 commit comments

Comments
 (0)