-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.coffee
More file actions
42 lines (37 loc) · 825 Bytes
/
test.coffee
File metadata and controls
42 lines (37 loc) · 825 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
32
33
34
35
36
37
38
39
40
41
42
{Actor} = require('./Actor.coffee')
class Adder extends Actor
constructor: ->
super {debug: true}
@$start
call:
sync_add: @add_sync
receive:
async_add: @add_async
add_sync: (a, b)=>
a + b
add_async: (from, msg)=>
setTimeout =>
@$send_to from, 'answer', msg.a + msg.b
# @$next() # to handle next msg after answering
@$terminate()
, 500
@$next() # to handle next msg immediately
class Asker extends Actor
constructor: ->
super
@$start
receive:
answer: (from, v)=>
@logger.log v
@$next()
DOWN: (from, v)=>
@logger.log 'terminating:', v
@$terminate()
asker = new Asker()
adder = new Adder()
ref = asker.$monitor adder
asker.$send_to adder, 'async_add',
a: 3
b: 5
# asker.$unmonitor ref # to unmonitor
asker.logger.log adder.$call 'sync_add', 4, 6