update
This commit is contained in:
15
package/node_modules/promise-all-reject-late/LICENSE
generated
vendored
Normal file
15
package/node_modules/promise-all-reject-late/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
The ISC License
|
||||
|
||||
Copyright (c) Isaac Z. Schlueter
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
||||
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
27
package/node_modules/promise-all-reject-late/index.js
generated
vendored
Normal file
27
package/node_modules/promise-all-reject-late/index.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
const allSettled =
|
||||
Promise.allSettled ? promises => Promise.allSettled(promises)
|
||||
: promises => {
|
||||
const reflections = []
|
||||
for (let i = 0; i < promises.length; i++) {
|
||||
reflections[i] = Promise.resolve(promises[i]).then(value => ({
|
||||
status: 'fulfilled',
|
||||
value,
|
||||
}), reason => ({
|
||||
status: 'rejected',
|
||||
reason,
|
||||
}))
|
||||
}
|
||||
return Promise.all(reflections)
|
||||
}
|
||||
|
||||
module.exports = promises => allSettled(promises).then(results => {
|
||||
let er = null
|
||||
const ret = new Array(results.length)
|
||||
results.forEach((result, i) => {
|
||||
if (result.status === 'rejected')
|
||||
throw result.reason
|
||||
else
|
||||
ret[i] = result.value
|
||||
})
|
||||
return ret
|
||||
})
|
22
package/node_modules/promise-all-reject-late/package.json
generated
vendored
Normal file
22
package/node_modules/promise-all-reject-late/package.json
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "promise-all-reject-late",
|
||||
"version": "1.0.1",
|
||||
"description": "Like Promise.all, but save rejections until all promises are resolved",
|
||||
"author": "Isaac Z. Schlueter <i@izs.me> (https://izs.me)",
|
||||
"license": "ISC",
|
||||
"scripts": {
|
||||
"test": "tap",
|
||||
"preversion": "npm test",
|
||||
"postversion": "npm publish",
|
||||
"prepublishOnly": "git push origin --follow-tags"
|
||||
},
|
||||
"tap": {
|
||||
"check-coverage": true
|
||||
},
|
||||
"devDependencies": {
|
||||
"tap": "^14.10.5"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/isaacs"
|
||||
}
|
||||
}
|
88
package/node_modules/promise-all-reject-late/test/index.js
generated
vendored
Normal file
88
package/node_modules/promise-all-reject-late/test/index.js
generated
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
const t = require('tap')
|
||||
|
||||
const main = () => {
|
||||
if (process.argv[2] === 'polyfill-all-settled') {
|
||||
Promise.allSettled = null
|
||||
runTests()
|
||||
} else if (process.argv[2] === 'native-all-settled') {
|
||||
Promise.allSettled = Promise.allSettled || (
|
||||
promises => {
|
||||
const reflections = []
|
||||
for (let i = 0; i < promises.length; i++) {
|
||||
reflections[i] = Promise.resolve(promises[i]).then(value => ({
|
||||
status: 'fulfilled',
|
||||
value,
|
||||
}), reason => ({
|
||||
status: 'rejected',
|
||||
reason,
|
||||
}))
|
||||
}
|
||||
return Promise.all(reflections)
|
||||
}
|
||||
)
|
||||
runTests()
|
||||
} else {
|
||||
t.spawn(process.execPath, [__filename, 'polyfill-all-settled'])
|
||||
t.spawn(process.execPath, [__filename, 'native-all-settled'])
|
||||
}
|
||||
}
|
||||
|
||||
const runTests = () => {
|
||||
const lateFail = require('../')
|
||||
|
||||
t.test('fail only after all promises resolve', t => {
|
||||
let resolvedSlow = false
|
||||
const fast = () => Promise.reject('nope')
|
||||
const slow = () => new Promise(res => setTimeout(res, 100))
|
||||
.then(() => resolvedSlow = true)
|
||||
|
||||
// throw some holes and junk in the array to verify that we handle it
|
||||
return t.rejects(lateFail([fast(),,,,slow(), null, {not: 'a promise'},,,]))
|
||||
.then(() => t.equal(resolvedSlow, true, 'resolved slow before failure'))
|
||||
})
|
||||
|
||||
t.test('works just like Promise.all() otherwise', t => {
|
||||
const one = () => Promise.resolve(1)
|
||||
const two = () => Promise.resolve(2)
|
||||
const tre = () => Promise.resolve(3)
|
||||
const fur = () => Promise.resolve(4)
|
||||
const fiv = () => Promise.resolve(5)
|
||||
const six = () => Promise.resolve(6)
|
||||
const svn = () => Promise.resolve(7)
|
||||
const eit = () => Promise.resolve(8)
|
||||
const nin = () => Promise.resolve(9)
|
||||
const ten = () => Promise.resolve(10)
|
||||
const expect = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
||||
const all = Promise.all([
|
||||
one(),
|
||||
two(),
|
||||
tre(),
|
||||
fur(),
|
||||
fiv(),
|
||||
six(),
|
||||
svn(),
|
||||
eit(),
|
||||
nin(),
|
||||
ten(),
|
||||
])
|
||||
const late = lateFail([
|
||||
one(),
|
||||
two(),
|
||||
tre(),
|
||||
fur(),
|
||||
fiv(),
|
||||
six(),
|
||||
svn(),
|
||||
eit(),
|
||||
nin(),
|
||||
ten(),
|
||||
])
|
||||
|
||||
return Promise.all([all, late]).then(([all, late]) => {
|
||||
t.strictSame(all, expect)
|
||||
t.strictSame(late, expect)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
main()
|
Reference in New Issue
Block a user