pad.js: fix freeze on pad deletion when it has many revisions

This commit is contained in:
Chocobozzz 2019-12-19 17:14:00 +01:00 committed by muxator
parent 09ddfb9e20
commit 53003d4471
2 changed files with 39 additions and 6 deletions

View file

@ -0,0 +1,32 @@
/**
* Helpers to manipulate promises (like async but for promises).
*/
var timesLimit = function (ltMax, concurrency, promiseCreator) {
var done = 0
var current = 0
function addAnother () {
function _internalRun () {
done++
if (done < ltMax) {
addAnother()
}
}
promiseCreator(current)
.then(_internalRun)
.catch(_internalRun)
current++
}
for (var i = 0; i < concurrency && i < ltMax; i++) {
addAnother()
}
}
module.exports = {
timesLimit: timesLimit
}