forked from asynkron/protoactor-go
/
options.go
52 lines (47 loc) · 1.3 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
47
48
49
50
51
52
package actor
import "github.com/ChaokunChang/protoactor-go/eventstream"
type optionFn func()
// WithDeadLetterSubscriber option replaces the default DeadLetterEvent event subscriber with fn.
//
// fn will only receive *DeadLetterEvent messages
//
// Specifying nil will clear the existing.
func WithDeadLetterSubscriber(fn func(evt interface{})) optionFn {
return func() {
if deadLetterSubscriber != nil {
eventstream.Unsubscribe(deadLetterSubscriber)
}
if fn != nil {
deadLetterSubscriber = eventstream.Subscribe(fn).
WithPredicate(func(m interface{}) bool {
_, ok := m.(*DeadLetterEvent)
return ok
})
}
}
}
// WithSupervisorSubscriber option replaces the default SupervisorEvent event subscriber with fn.
//
// fn will only receive *SupervisorEvent messages
//
// Specifying nil will clear the existing.
func WithSupervisorSubscriber(fn func(evt interface{})) optionFn {
return func() {
if supervisionSubscriber != nil {
eventstream.Unsubscribe(supervisionSubscriber)
}
if fn != nil {
supervisionSubscriber = eventstream.Subscribe(fn).
WithPredicate(func(m interface{}) bool {
_, ok := m.(*SupervisorEvent)
return ok
})
}
}
}
// SetOptions is used to configure the actor system
func SetOptions(opts ...optionFn) {
for _, opt := range opts {
opt()
}
}