-
Notifications
You must be signed in to change notification settings - Fork 5
/
concur.edh
45 lines (35 loc) · 1.18 KB
/
concur.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
{
# fake some time costing works to do
generator allWorksToDo( nJobs=10, leastSeconds=3 ) {
# use this proc to capture a local copy of the arguments for the task
method longthyWork( job'num, seconds2take ) method _ () {
# this anonymous nullary proc defines the task in form of niladic computation
console.info <| ' 🏎️ #' ++ job'num ++ ' started'
n = 0
for nanos from console.everySeconds( 1 )
do if ( n+=1 ) >= seconds2take then {
console.info <| ' 🏁 #' ++ job'num ++ ' done'
break
} else {
# uncomment line below to see even more verbose log
console.info <| ' 📝 #' ++ job'num ++ ' tick ' ++ nanos
}
}
for n from range( nJobs ) do yield longthyWork( n, leastSeconds + n )
}
}
{
{#
# `concur()` is the sorta primitive for concurrency scheduling,
# it's a plain Edh method procedure defined in `batteries/root`
# module so automically available in a Edh world, its signature
# looks like following:
# method concur(*tasks, c=6, dbgLogger=0) {
# ...
# }
#}
concur(
* () =< for work from allWorksToDo( 10, 3 ) do work,
c=5, dbgLogger=console.info,
)
}