mirror of https://github.com/seald/nedb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
792 B
34 lines
792 B
3 years ago
|
const { callbackify, promisify } = require('util')
|
||
|
|
||
|
const waterfallAsync = async tasks => {
|
||
|
for (const task of tasks) {
|
||
|
await promisify(task)()
|
||
|
}
|
||
|
}
|
||
|
|
||
|
const waterfall = callbackify(waterfallAsync)
|
||
|
|
||
|
const eachAsync = async (arr, iterator) => Promise.all(arr.map(el => promisify(iterator)(el)))
|
||
|
|
||
|
const each = callbackify(eachAsync)
|
||
|
|
||
|
const apply = function (fn) {
|
||
|
const args = Array.prototype.slice.call(arguments, 1)
|
||
|
return function () {
|
||
|
return fn.apply(
|
||
|
null, args.concat(Array.prototype.slice.call(arguments))
|
||
|
)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
const whilstAsync = async (test, fn) => {
|
||
|
while (test()) await promisify(fn)()
|
||
|
}
|
||
|
|
||
|
const whilst = callbackify(whilstAsync)
|
||
|
|
||
|
module.exports.whilst = whilst
|
||
|
module.exports.apply = apply
|
||
|
module.exports.waterfall = waterfall
|
||
|
module.exports.each = each
|