-
-
Notifications
You must be signed in to change notification settings - Fork 523
/
actor.go
48 lines (38 loc) · 1.34 KB
/
actor.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
package actor
// The Producer type is a function that creates a new actor
type Producer func() Actor
// Actor is the interface that defines the Receive method.
//
// Receive is sent messages to be processed from the mailbox associated with the instance of the actor
type Actor interface {
Receive(c Context)
}
// The ActorFunc type is an adapter to allow the use of ordinary functions as actors to process messages
type ActorFunc func(c Context)
// Receive calls f(c)
func (f ActorFunc) Receive(c Context) {
f(c)
}
type SenderFunc func(c Context, target *PID, envelope *MessageEnvelope)
//FromProducer creates a props with the given actor producer assigned
func FromProducer(actorProducer Producer) *Props {
return &Props{actorProducer: actorProducer}
}
//FromFunc creates a props with the given receive func assigned as the actor producer
func FromFunc(f ActorFunc) *Props {
return FromProducer(func() Actor { return f })
}
func FromSpawnFunc(spawn SpawnFunc) *Props {
return &Props{spawner: spawn}
}
//Deprecated: FromInstance is deprecated
//Please use FromProducer(func() actor.Actor {...}) instead
func FromInstance(template Actor) *Props {
return &Props{actorProducer: makeProducerFromInstance(template)}
}
//Deprecated: makeProducerFromInstance is deprecated.
func makeProducerFromInstance(a Actor) Producer {
return func() Actor {
return a
}
}