forked from vespina/promises
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample_lambda.prg
More file actions
38 lines (32 loc) · 902 Bytes
/
Copy pathsample_lambda.prg
File metadata and controls
38 lines (32 loc) · 902 Bytes
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
SET PROCEDURE TO promises.prg
CLEAR
=RAND(SECONDS())
LOCAL fun, funthen, funcatch
fun = lambda('(i, counter) => ;;
m.counter.cntMax = MAX(INT(RAND() * 5000), 1) ;;
m.counter.msg = TEXTMERGE("AsyncFunc<<m.i>>: ") ;;
RETURN AsyncRun(m.counter)')
m.funthen = lambda('(res) => ? TRANSFORM(m.res) + " then " + SYS(2015)')
m.funcatch = lambda('(err) => ? err.Message')
PUBLIC paTasks[1]
LOCAL i
FOR i = 1 TO 100
DIMENSION paTasks(m.i)
paTasks[m.i] = AsyncRun(fun, m.i, CREATEOBJECT("Counter"))
WITH paTasks[m.i]
.then(m.funthen)
.catch(m.funcatch)
ENDWITH
ENDFOR
DEFINE CLASS Counter as Callable
cnt = 0
cntMax = 0
msg = ''
FUNCTION call
This.cnt = This.cnt + 1
IF This.cnt < This.cntMax
RETURN AsyncRepeat()
ENDIF
RETURN This.msg + TEXTMERGE("counted to <<This.cnt>>")
ENDFUNC
ENDDEFINE