test-any.coffee
1.26 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
# This is a test case for petkaantonov/bluebird#432, encountered during development of this module.
Promise = require "bluebird"
successPromise = (val) ->
new Promise (resolve, reject) ->
process.nextTick -> resolve(val)
failurePromise = (val) ->
new Promise (resolve, reject) ->
process.nextTick -> reject(val)
successSyncPromise = (val) ->
new Promise (resolve, reject) ->
resolve(val)
failureSyncPromise = (val) ->
new Promise (resolve, reject) ->
reject(val)
failureSyncPromiseTwo = (val) ->
Promise.reject(val)
Promise.any [
successSyncPromise()
successPromise()
failureSyncPromise("fail a").catch (err) -> console.log err
]
.then -> console.log "success a"
Promise.any [
successSyncPromise()
successPromise()
failurePromise("fail b").catch (err) -> console.log err
]
.then -> console.log "success b"
Promise.any [
successPromise()
successPromise()
failurePromise("fail c").catch (err) -> console.log err
]
.then -> console.log "success c"
Promise.any [
successSyncPromise()
successSyncPromise()
failureSyncPromise("fail d").catch (err) -> console.log err
]
.then -> console.log "success d"
Promise.any [
successSyncPromise()
successSyncPromise()
failureSyncPromiseTwo("fail e").catch (err) -> console.log err
]
.then -> console.log "success e"