teddit/node_modules/stream-length/test-any.coffee
2020-11-17 21:44:32 +01:00

60 lines
1.3 KiB
CoffeeScript

# 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"