-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.go
46 lines (38 loc) · 1.03 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright (c) 2019,CAO HONGJU. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package scheduler
import (
"context"
"time"
)
// An Option configures a Scheduler.
type Option interface {
apply(*Scheduler)
}
// optionFunc wraps a func so it satisfies the Option interface.
type optionFunc func(*Scheduler)
func (f optionFunc) apply(s *Scheduler) {
f(s)
}
// WithContext configures the context of the Scheduler.
func WithContext(ctx context.Context) Option {
return optionFunc(func(s *Scheduler) {
s.ctx, s.cancel = context.WithCancel(ctx)
})
}
// WithLocation configures the location of the Scheduler.
func WithLocation(location *time.Location) Option {
return optionFunc(func(s *Scheduler) {
s.loc = location
})
}
// WithPanicHandler configures the panic exception handler.
func WithPanicHandler(panicHandler PanicHandler) Option {
return optionFunc(func(s *Scheduler) {
if panicHandler == nil {
return
}
s.panicHandler.Store(panicHandler)
})
}