-
-
Notifications
You must be signed in to change notification settings - Fork 524
/
props.go
105 lines (88 loc) · 3.05 KB
/
props.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package actor
import "github.com/AsynkronIT/protoactor-go/mailbox"
type InboundMiddleware func(next ActorFunc) ActorFunc
type OutboundMiddleware func(next SenderFunc) SenderFunc
// Props represents configuration to define how an actor should be created
type Props struct {
actorProducer Producer
mailboxProducer mailbox.Producer
guardianStrategy SupervisorStrategy
supervisionStrategy SupervisorStrategy
inboundMiddleware []InboundMiddleware
outboundMiddleware []OutboundMiddleware
dispatcher mailbox.Dispatcher
spawner SpawnFunc
}
func (props *Props) getDispatcher() mailbox.Dispatcher {
if props.dispatcher == nil {
return defaultDispatcher
}
return props.dispatcher
}
func (props *Props) getSupervisor() SupervisorStrategy {
if props.supervisionStrategy == nil {
return defaultSupervisionStrategy
}
return props.supervisionStrategy
}
func (props *Props) produceMailbox(invoker mailbox.MessageInvoker, dispatcher mailbox.Dispatcher) mailbox.Inbound {
if props.mailboxProducer == nil {
return defaultMailboxProducer(invoker, dispatcher)
}
return props.mailboxProducer(invoker, dispatcher)
}
func (props *Props) spawn(id string, parent *PID) (*PID, error) {
if props.spawner != nil {
return props.spawner(id, props, parent)
}
return DefaultSpawner(id, props, parent)
}
// Assign one or more middlewares to the props
func (props *Props) WithMiddleware(middleware ...InboundMiddleware) *Props {
props.inboundMiddleware = append(props.inboundMiddleware, middleware...)
return props
}
func (props *Props) WithOutboundMiddleware(middleware ...OutboundMiddleware) *Props {
props.outboundMiddleware = append(props.outboundMiddleware, middleware...)
return props
}
//WithMailbox assigns the desired mailbox producer to the props
func (props *Props) WithMailbox(mailbox mailbox.Producer) *Props {
props.mailboxProducer = mailbox
return props
}
//WithGuardian assigns a guardian strategy to the props
func (props *Props) WithGuardian(guardian SupervisorStrategy) *Props {
props.guardianStrategy = guardian
return props
}
//WithSupervisor assigns a supervision strategy to the props
func (props *Props) WithSupervisor(supervisor SupervisorStrategy) *Props {
props.supervisionStrategy = supervisor
return props
}
//WithDispatcher assigns a dispatcher to the props
func (props *Props) WithDispatcher(dispatcher mailbox.Dispatcher) *Props {
props.dispatcher = dispatcher
return props
}
//WithSpawnFunc assigns a custom spawn func to the props, this is mainly for internal usage
func (props *Props) WithSpawnFunc(spawn SpawnFunc) *Props {
props.spawner = spawn
return props
}
//WithFunc assigns a receive func to the props
func (props *Props) WithFunc(f ActorFunc) *Props {
props.actorProducer = func() Actor { return f }
return props
}
//WithProducer assigns a actor producer to the props
func (props *Props) WithProducer(p Producer) *Props {
props.actorProducer = p
return props
}
//Deprecated: WithInstance is deprecated.
func (props *Props) WithInstance(a Actor) *Props {
props.actorProducer = makeProducerFromInstance(a)
return props
}