A nodejs project.I've tried to run plenty(about 100k) task sequently with promises. What I can do is converting it to a workOnebyOne function with Q. Is there a better way to do this?
function workOnebyOne(items, worker) {
var deferred = Q.defer()
function _doNext() {
if (items.length === 0) {
deferred.resolve()
return
}
var item = items[0]
synchronize(worker, item)
.then(function (result) {
items = items.slice(1)
deferred.notify({
item: item,
result: result
})
_doNext()
}, function () {
items = items.slice(1)
_doNext()
})
}
_doNext()
return deferred.promise
}
utils.workOnebyOne(tasks, workerFunction)