-
Notifications
You must be signed in to change notification settings - Fork 14
/
mq.rho
70 lines (70 loc) · 1.87 KB
/
mq.rho
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
new result, stdout(`rho:io:stdout`), stdoutAck(`rho:io:stdoutAck`), log, logList, mq in {
contract mq(ret) = {
new head, tail, pub, sub in {
tail!(*head) |
ret!(*pub, *sub) |
contract sub(listener) = {
new loop, ack in {
loop!(*head) |
contract loop(curr) = {
for (value, next <<- curr) {
result!(["got next",*value]) |
listener!(*value, *ack) |
stdout!(["got next",*value]) |
result!("listener called for " ++ *value) |
for ( _ <- ack) {
result!(["listener returned",*value]) |
stdout!(["sent",*value]) |
loop!(*next)
}
}
}
}
} |
contract pub(value, ret) = {
new newTail in {
for (end <- tail) {
end!(*value, *newTail) |
tail!(*newTail) |
log!("pub: " ++ *value, *ret)
}
}
}
}
}|
new listener, ret in {
contract listener(value, ack) = {
result!(*value ++ " listener")|
log!("received: " ++ *value, *ack )
} |
mq!(*ret) |
for ( pub, sub <- ret) {
sub!(*listener) |
pub!("one",*ret) |
for ( _ <- ret) {
pub!("two", *ret) |
for ( _ <- ret ) {
pub!("three", *ret) |
for ( _ <- ret ) {
pub!("four", *ret) |
for ( _ <- ret ) {
log!("done", *ret) |
for (_ <- ret; alist <- logList ) {
stdout!(*alist)|
result!({ "log":*alist})
}
}
}
}
}
} |
logList!([]) |
contract log(term, ack) = {
for ( prior <- logList) {
stdout!("logged: " ++ *term) |
logList!(*prior ++ [*term]) |
ack!(Nil)
}
}
}
}