forked from asynkron/protoactor-go
/
props.go
47 lines (39 loc) · 1023 Bytes
/
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
package gam
type Properties interface {
ProduceActor() Actor
Mailbox() Mailbox
Supervisor() SupervisionStrategy
}
type PropsValue struct {
actorProducer ActorProducer
mailbox Mailbox
supervisionStrategy SupervisionStrategy
}
func (props PropsValue) ProduceActor() Actor {
return props.actorProducer()
}
func (props PropsValue) Supervisor() SupervisionStrategy {
return props.supervisionStrategy
}
func (props PropsValue) Mailbox() Mailbox {
if props.mailbox == nil {
return NewUnboundedMailbox()
}
return props.mailbox
}
func Props(actorProducer ActorProducer) PropsValue {
return PropsValue{
actorProducer: actorProducer,
mailbox: nil,
}
}
func (props PropsValue) WithMailbox(mailbox Mailbox) PropsValue {
//pass by value, we only modify the copy
props.mailbox = mailbox
return props
}
func (props PropsValue) WithSupervisor(supervisor SupervisionStrategy) PropsValue {
//pass by value, we only modify the copy
props.supervisionStrategy = supervisor
return props
}