When I use promises to express dependencies between jobs where the resolved value becomes irrelevant, there is a certain danger that I might forget about the return somewhere. Example:
startSomething().then(function() { Q.all(tasks.map(function(task) { return task.startIt(); })) }).then(collectOutput).done();
Here Q.all returns the promise, and I had to return it. Not doing this means that by the time collectOutput all tasks were started, but there was no guarantee that they had finished.
Such an error leads to a race condition, and it is very difficult to reproduce and track. Therefore, I am wondering if there is any tool that will help to detect and avoid such a problem? Perhaps some kind of promise library that warns when a function returns undefined along the way? Or discovers promises without listeners, like Bluebird does for raw failures?
source share