This repository has been archived by the owner on Sep 2, 2023. It is now read-only.
/
pid_option.go
77 lines (65 loc) · 1.79 KB
/
pid_option.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package actors
import (
"time"
"github.com/super-flat/actors/log"
pb "github.com/super-flat/actors/pb/actors/v1"
"github.com/super-flat/actors/telemetry"
)
// pidOption represents the pid
type pidOption func(pid *pid)
// withPassivationAfter sets the actor passivation time
func withPassivationAfter(duration time.Duration) pidOption {
return func(pid *pid) {
pid.passivateAfter = duration
}
}
// withSendReplyTimeout sets how long in seconds an actor should reply a command
// in a receive-reply pattern
func withSendReplyTimeout(timeout time.Duration) pidOption {
return func(pid *pid) {
pid.sendReplyTimeout = timeout
}
}
// withInitMaxRetries sets the number of times to retry an actor init process
func withInitMaxRetries(max int) pidOption {
return func(pid *pid) {
pid.initMaxRetries = max
}
}
// withCustomLogger sets the logger
func withCustomLogger(logger log.Logger) pidOption {
return func(pid *pid) {
pid.logger = logger
}
}
// withActorSystem set the actor system of the pid
func withActorSystem(sys ActorSystem) pidOption {
return func(pid *pid) {
pid.system = sys
}
}
// withSupervisorStrategy sets the supervisor strategy to used when dealing
// with child actors
func withSupervisorStrategy(strategy pb.StrategyDirective) pidOption {
return func(pid *pid) {
pid.supervisorStrategy = strategy
}
}
// withShutdownTimeout sets the shutdown timeout
func withShutdownTimeout(duration time.Duration) pidOption {
return func(pid *pid) {
pid.shutdownTimeout = duration
}
}
// withNoPassivation disable passivation
func withPassivationDisabled() pidOption {
return func(pid *pid) {
pid.passivateAfter = -1
}
}
// withTelemetry sets the custom telemetry
func withTelemetry(telemetry *telemetry.Telemetry) pidOption {
return func(pid *pid) {
pid.telemetry = telemetry
}
}