I\'m using babeljs with es7 style async/await methods. I have a main script that will call a async method on an array of objects that all return promises. I use Promise.al
This really depends on the API you need to use. Most of the current async API methods of node aren't easily "interruptible" (readfileasync and the likes), unless you yourself do your own implementation of them.
There is no easy way to easily cancel a scheduled dispatch. The API so far is not built with this thing in mind. Promises also can't help when low level implementations of API don't support aborting.
But in some API's you get to intercept process "steps", such as streams on data events and the "next tick" implementations. There you can abort the further processing. (Streams are actually pretty good candidate for implementing intercept-able IO stuff)
The classic node example, where a fibonacci sequence calculation of input "n" is served per request, the logic is implemented via "next tick". There you can actually set a timeout on the calculation and server automatically kicks long running requests:
var do_fibonacci_async = function(a,limiter,callback){
if(limiter.halt){
callback(limiter.msg);
}
else if(a <= 2){
callback(limiter.halt ? limiter.msg : 1);
}else{
process.nextTick(function(){
do_fibonacci_async(a - 1,limiter, function(val1){
do_fibonacci_async(a - 2,limiter, function(val2){
callback(limiter.halt ? limiter.msg : val1+val2);
});
});
});
}
}
exports.fibonacci_async = function(a,callback){
if(!a || isNaN(a)){
callback(new out("fibonacci", [], ""));
return;
}
var limiter = {halt:false, msg:"Too large to compute"};
setTimeout(function(){
limiter.halt = true;
},5000);
do_fibonacci_async(a,limiter,function(val){
callback(new out("fibonacci", [a], val));
});
}