-
Notifications
You must be signed in to change notification settings - Fork 95
/
main.go
47 lines (39 loc) · 850 Bytes
/
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
package main
import (
"fmt"
"sync"
"time"
"github.com/anthdm/hollywood/actor"
)
type message struct {
data string
}
var wg sync.WaitGroup
type foo struct{}
func newFoo() actor.Receiver {
return &foo{}
}
func (f *foo) Receive(ctx *actor.Context) {
switch msg := ctx.Message().(type) {
case actor.Started:
fmt.Println("foo started")
case *message:
if msg.data == "failed" {
panic("I failed processing this message")
}
wg.Done()
fmt.Println("I restarted and processed the next one perfectly:", msg.data)
}
}
func main() {
engine, err := actor.NewEngine(actor.NewEngineConfig())
if err != nil {
panic(err)
}
pid := engine.Spawn(newFoo, "foo", actor.WithMaxRestarts(3))
wg.Add(1)
engine.Send(pid, &message{data: "failed"})
time.Sleep(time.Millisecond)
engine.Send(pid, &message{data: "hello world!"})
wg.Wait()
}