forked from asynkron/protoactor-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
local.go
40 lines (34 loc) · 746 Bytes
/
local.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
package main
import (
"sync"
"github.com/AsynkronIT/protoactor-go/actor"
"github.com/AsynkronIT/protoactor-go/examples/remoterouting/messages"
"log"
)
type localActor struct {
count int
wgStop *sync.WaitGroup
messageCount int
}
func (state *localActor) Receive(context actor.Context) {
switch context.Message().(type) {
case *messages.Pong:
state.count++
if state.count%50000 == 0 {
log.Println(state.count)
}
if state.count == state.messageCount {
log.Println("Done")
state.wgStop.Done()
}
}
}
func newLocalActor(stop *sync.WaitGroup, messageCount int) actor.Producer {
stop.Add(1)
return func() actor.Actor {
return &localActor{
wgStop: stop,
messageCount: messageCount,
}
}
}