-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.coffee
68 lines (52 loc) · 1.18 KB
/
demo.coffee
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
61
62
63
64
65
66
67
68
###
Demo script for the different styles
###
#A useless asynchronous function for demo purposes
someAsyncCall = (cb) -> setTimeout cb, 500 + 500*Math.random()
op = new DelayedOp 'Demo'
###
The simplest call style
If your waits and oks are imbalanced, this style is not helpful in finding the
problem.
###
op.wait()
someAsyncCall ->
console.log 'Simple style'
op.ok()
###
Simple call style with tag
If your calls are unbalanced, you will at least know which tag it was.
###
op.wait 'tag'
someAsyncCall ->
console.log 'Tagged simple style'
op.ok 'tag'
###
Callback style
The callback is passed its very own 'ok' function which throws an exception if it is called twice.
###
op.wait (ok) -> someAsyncCall ->
console.log 'Callback style'
ok()
###
Callback style with tag
Just a tad more information for debugging
###
op.wait 'tag', (ok) -> someAsyncCall ->
console.log 'Tagged callback style'
ok() #you don't have to pass the tag in this style
###
Return style
###
ok = op.wait()
someAsyncCall ->
console.log 'Return style'
ok()
###
Return style with tag
###
ok2 = op.wait 'tag'
someAsyncCall ->
console.log 'Tagged return style'
ok2()
op.ready -> alert 'All operations have completed.'