forked from vespina/promises
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample_asyncrun.prg
More file actions
48 lines (40 loc) · 1.14 KB
/
Copy pathsample_asyncrun.prg
File metadata and controls
48 lines (40 loc) · 1.14 KB
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
SET PROCEDURE TO promises.prg
CLEAR
=RAND(SECONDS())
PUBLIC paTasks[1]
LOCAL i
FOR i = 1 TO 1000
DIMENSION paTasks(m.i)
paTasks[m.i] = AsyncRun("MyAsyncFunc", MAX(INT(RAND() * 5000), 1), TEXTMERGE("AsyncFunc<<m.i>>: "))
WITH paTasks[m.i]
.then("MyPromiseThen")
ENDWITH
ENDFOR
DEFINE CLASS MyAsyncFunc as Callable
FUNCTION call(cntMax as Integer, msg as String)
RETURN AsyncRun("MyAsyncFuncNested", m.cntMax, m.msg)
ENDFUNC
ENDDEFINE
DEFINE CLASS MyAsyncFuncNested as Callable
FUNCTION call(cntMax as Integer, msg as String)
RETURN AsyncRun("MyAsyncFuncNestedNested", m.cntMax, m.msg)
ENDFUNC
ENDDEFINE
DEFINE CLASS MyAsyncFuncNestedNested as Callable
cnt = 0
FUNCTION call(cntMax as Integer, msg as String)
This.cnt = This.cnt + 1
IF This.cnt != m.cntMax
RETURN AsyncRepeat()
ENDIF
RETURN m.msg + TEXTMERGE("counted to <<This.cnt>>")
ENDFUNC
ENDDEFINE
DEFINE CLASS MyPromiseThen as Callable
FUNCTION call(value)
LOCAL res
m.res = TRANSFORM(m.value) + " then " + SYS(2015)
? m.res
RETURN m.res
ENDFUNC
ENDDEFINE