You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
523 B
JavaScript
26 lines
523 B
JavaScript
"use strict";
|
|
|
|
const Promise = require("bluebird");
|
|
|
|
module.exports = function runDisposableQueue(items, processingCallback) {
|
|
let itemIndex = 0; // FIXME: overflow
|
|
|
|
function processItem() {
|
|
let disposeFlag = false;
|
|
|
|
return Promise.try(() => {
|
|
let item = items[itemIndex];
|
|
itemIndex += 1;
|
|
|
|
return processingCallback(item, () => {
|
|
disposeFlag = true;
|
|
});
|
|
}).then(() => {
|
|
if (disposeFlag === false && itemIndex < items.length) {
|
|
return processItem();
|
|
}
|
|
});
|
|
}
|
|
|
|
return processItem();
|
|
}; |