promise with timeout
var p = trySomeAsyncThing(); Promise.race([ p, new Promise(function(_, reject) { setTimeout(function() { reject("Timeout!!"); }, 3000); }) ]) .then(success, error);