-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsample_simplified.prg
More file actions
60 lines (50 loc) · 1.29 KB
/
sample_simplified.prg
File metadata and controls
60 lines (50 loc) · 1.29 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
49
50
51
52
53
54
55
56
57
58
59
60
SET PROCEDURE TO promises.prg
CLEAR
* Interval
WITH CREATEOBJECT("MyInterval")
.promise = Promise()
.SetInterval(10, 15, "Hello, Interval!")
WITH .promise
WITH .then(CREATEOBJECT("MyPromiseThen"))
WITH .then("MyPromiseThen")
.then(CREATEOBJECT("MyPromiseThen"))
ENDWITH
ENDWITH
.then(CREATEOBJECT("MyPromiseThen"))
ENDWITH
ENDWITH
* Timeout
WITH CREATEOBJECT("MyTimeout")
.promise = Promise()
.SetTimeout(100, "Hello, Timeout!")
WITH .promise.then("MyPromiseThen")
.then("MyPromiseThen")
ENDWITH
ENDWITH
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
DEFINE CLASS MyInterval as IntervalCallable
cnt = 0
promise = NULL
FUNCTION call(cntMax as Integer, msg as String)
This.cnt = This.cnt + 1
? this.cnt
IF This.cnt = m.cntMax
This.promise.resolve(m.msg)
This.ClearInterval()
ENDIF
ENDFUNC
ENDDEFINE
DEFINE CLASS MyTimeout as TimeoutCallable
promise = NULL
FUNCTION call(msg as String)
This.promise.resolve(m.msg)
This.ClearTimeout()
ENDFUNC
ENDDEFINE