-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelayer.go
63 lines (53 loc) · 1.6 KB
/
delayer.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package delaying
import "context"
type Delayer interface {
ID() string
Implementation() any
EnqueueWork(c context.Context, params Params, args ...interface{}) error
EnqueueWorkMulti(c context.Context, params Params, args ...[]interface{}) error
}
// Deprecated: Use Delayer instead.
type Function = Delayer
// NewDelayer creates a new Delayer.
func NewDelayer(
id string,
implementation any,
enqueueWork func(c context.Context, params Params, args ...interface{}) error,
enqueueWorkMulti func(c context.Context, params Params, args ...[]interface{}) error,
) Delayer {
if implementation == nil {
panic("implementation is nil")
}
if enqueueWork == nil {
panic("enqueueWork is nil")
}
if enqueueWorkMulti == nil {
panic("enqueueWorkMulti is nil")
}
return delayer{
id: id,
implementation: implementation,
enqueueWork: enqueueWork,
enqueueWorkMulti: enqueueWorkMulti,
}
}
// Deprecated: Use NewDelayer instead.
var NewFunction = NewDelayer
type delayer struct {
id string
implementation any
enqueueWork func(c context.Context, params Params, args ...interface{}) error
enqueueWorkMulti func(c context.Context, params Params, args ...[]interface{}) error
}
func (f delayer) ID() string {
return f.id
}
func (f delayer) Implementation() any {
return f.implementation
}
func (f delayer) EnqueueWork(c context.Context, params Params, args ...interface{}) error {
return f.enqueueWork(c, params, args...)
}
func (f delayer) EnqueueWorkMulti(c context.Context, params Params, args ...[]interface{}) error {
return f.enqueueWorkMulti(c, params, args...)
}