-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsupervisor.js
More file actions
31 lines (24 loc) · 759 Bytes
/
supervisor.js
File metadata and controls
31 lines (24 loc) · 759 Bytes
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
let { Actor, ActorSystem, ActorSystemConfigurationBuilder } = require('../dist/index')
class Clock extends Actor {
constructor(times, message) {
super()
this.times = times
this.timer = this.schedule(250, this.tick, [message])
}
async tick(message) {
console.log(this.times, "From clock ", this.id, " message:", message)
if (Math.random() < 0.5) {
throw 'random failure'
}
if (--this.times <= 0) {
this.cancel(this.timer)
}
}
}
let system = ActorSystem.for(ActorSystemConfigurationBuilder.define()
.withTopSupervisor(() => "retry-message")
.done())
system.actorOf(Clock, [10, "Actors are cool"])
setTimeout(() => {
system.free()
}, 3000)