-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathproducer.edh
41 lines (33 loc) · 1.17 KB
/
producer.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
# %%
{
# a producer procedure always runs in a forked thread, its return
# value will be ignored anyway, but its caller will always receive
# a `chan` as if returned by the producer procedure.
#
# the `chan` will be passed to the producer procedure as `outlet`
# arg as well, so the caller acts as the consumer of this producer.
producer timelyAlert (
interval,
cnt= 3,
# the `outlet` arg is always filled, if not explicitly passed by
# the caller, Edh will create a new `chan`, to be returned to the
# caller as well as passed to this producer procedure as `outlet`.
outlet= chan
# have it a default value to fool the lint/IDE tooling to believe
# it's an optional argument for the caller. this is not necessary
# for correct behavior though.
) {
defer outlet <-nil # close the channel anyway after we're done
outlet <- 'start alerting you every ' ++ interval ++ ' second(s) ...'
for ts from console.everySeconds( interval ) do {
outlet <- '⏰ alarm (' ++cnt++ ') @@ ' ++ ts
if (cnt -= 1) <= 0 then break
}
}
}
# %%
{
for notif from timelyAlert( 1 ) do {
console.info<| ' ALARM - ' ++ notif
}
}