-
-
Notifications
You must be signed in to change notification settings - Fork 515
/
main.go
49 lines (41 loc) · 1.08 KB
/
main.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
package main
import (
"fmt"
console "github.com/AsynkronIT/goconsole"
"github.com/AsynkronIT/protoactor-go/actor"
)
type Hello struct{ Who string }
type SetBehaviorActor struct {
behavior actor.Behavior
}
func (state *SetBehaviorActor) Receive(context actor.Context) {
state.behavior.Receive(context)
}
func (state *SetBehaviorActor) One(context actor.Context) {
switch msg := context.Message().(type) {
case Hello:
fmt.Printf("Hello %v\n", msg.Who)
state.behavior.Become(state.Other)
}
}
func (state *SetBehaviorActor) Other(context actor.Context) {
switch msg := context.Message().(type) {
case Hello:
fmt.Printf("%v, ey we are now handling messages in another behavior", msg.Who)
}
}
func NewSetBehaviorActor() actor.Actor {
act := &SetBehaviorActor{
behavior: actor.NewBehavior(),
}
act.behavior.Become(act.One)
return act
}
func main() {
rootContext := actor.EmptyRootContext
props := actor.PropsFromProducer(NewSetBehaviorActor)
pid := rootContext.Spawn(props)
rootContext.Send(pid, Hello{Who: "Roger"})
rootContext.Send(pid, Hello{Who: "Roger"})
console.ReadLine()
}