-
Notifications
You must be signed in to change notification settings - Fork 2
/
any.js
25 lines (24 loc) · 705 Bytes
/
any.js
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
var promise = require('./index')
promise.resolve = require('./resolve')
module.exports = function any (values) {
function flip (p) {
return promise(function (resolve, reject) {
promise.resolve(p).then(reject, resolve)
})
}
return flip(promise(function (resolve, reject) {
var l
var counter = l = values && values.length
if (!counter) return reject(values)
for (var i = 0; i < l; i++) { loop(values[i], i) }
function loop (val, l) {
if (val && typeof val.then === 'function') {
return flip(val.then(reject, function decrement (val) {
values[l] = val
--counter || resolve(values)
}))
}
reject(val)
}
}))
}