-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathtest.yaml
69 lines (57 loc) · 1.5 KB
/
test.yaml
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
name: test
doc: |
A little three-node machine that emits messages that depend on a
parameter and a counter.
When given a message like
{"message":{"wants":"tacos"}}
and assuming a parameters
{"has": "beer", "n": 3}
the machine will emit a message like
{"server": "tacos", "with": "beer", "remaining": 2}
Subsequent requests decrement the counter until it reaches 0, at
which point the binding for "has" changes to "water".
paramspecs:
has:
doc: What the user has on hand.
primitiveType: string
n:
doc: The number that we have.
primitiveType: int
patternsyntax: json
nodes:
start:
doc: |
The starting node. Waits for the right kind of message.
branching:
type: message
branches:
- pattern: |
{"message":{"wants":"?wants"}}
target: deliver
deliver:
doc: |
Decrement the counter and emit a message.
action:
interpreter: ecmascript
source: |
var remaining = _.bindings["n"] - 1;
_.bindings["n"] = remaining;
_.out({serve: _.bindings["?wants"], with: _.bindings["has"], remaining: remaining});
delete _.bindings["?wants"];
return _.bindings;
branching:
branches:
- pattern: |
{"n": 0}
target: change
- target: start
change:
doc: |
Insist on water from now on.
action:
interpreter: ecmascript
source: |
return {n: 1, has: "water"};
branching:
branches:
- target: start