-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpipe-async.edh
82 lines (62 loc) · 1.45 KB
/
pipe-async.edh
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
71
72
73
74
75
76
77
78
79
80
81
82
# producer procedures are syntatically very appealing to be used in data pipeline
# definition and assembling
# %{
# %%
producer add3( intake, outlet ) {
for x from intake do outlet <- {
x+3
}
} @=> outlet <-nil # finally mark end-of-stream
# %%
producer mul5( intake, outlet ) {
for x from intake do outlet <- {
x*5
}
} @=> outlet <-nil # finally mark end-of-stream
# %%
producer somePipeline ( intake, outlet ) {
for y from (
intake | add3 | mul5
) do outlet <- y
} @=> outlet <-nil # finally mark end-of-stream
# %}
# %%
producer someStreamIn( bias, outlet ) {
outlet <- 3+bias
outlet <- 11+bias
outlet <- 2+bias
outlet <-nil # mark end-of-stream
}
# %%
console.print$ ' * the input series:'
for y from someStreamIn( 300 ) do {
console.print( y )
}
# %%
console.print$ ' * the output series:'
for y from someStreamIn( 300 ) | somePipeline do {
console.print( y )
}
# %{
# %%
# producer based pipelines can be fed lazily / interactively,
# due to the async nature
feedIn = chan
perceive (
feedIn | add3 | mul5
) { y } -> {
# note the output to terminal via console.print can be blocked by repl,
# so better to use console log here
console.info<| 'pipe yielded a value: ' ++ y
}
# %%
feedIn <- 3 + 300
# %%
feedIn <- 11 + 300
# %%
feedIn <- 2 + 300
# %}
# %%
# wait a tiny bit to see all async induced logs, in case this file
# is run by runedh instead of interactively
for _ from console.everyMillis( 10 ) do { break }