forked from Comcast/plax
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatch.yaml
28 lines (28 loc) · 892 Bytes
/
match.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
doc: |
An example of using 'match' in Javascript.
labels:
- selftest
spec:
phases:
phase1:
steps:
- "$include<include/mock.yaml>"
- sub:
pattern: test
- pub:
topic: test
payload: '{"want":"queso","when":"now"}'
- recv:
pattern: '{"want":"?x"}'
timeout: '2s'
guard: |
// Silly to do this 'match' here when we could have done it
// with the 'recv' pattern. Just shows calling 'match'
// from Javascript.
print("msg", msg);
var pat = {"when":"?w"}; // Our pattern
var bs0 = {}; // Input bindings for 'match'.
// msg.Payload is a raw string.
var bss = match(pat, JSON.parse(msg.Payload), bs0);
var w = bss[0]["?w"];
return w == "now";