-
Notifications
You must be signed in to change notification settings - Fork 396
when timeout
Brian Cavalier edited this page Feb 2, 2012
·
3 revisions
The when/timeout helper creates a promise that automatically rejects after a specified time, if not resolved before that. This allows you to setup up scenarios where a computation must finish within a certain time, or be rejected.
var timeout = require('when/timeout');
function doSomething() {
// Kickoff a slow, asynchronous calculation
var slowCalculationPromise = when(doSlowAsyncCalculation());
// Return a new promise that will resolve if doSlowAsyncCalculation finishes
// in under 5 seconds, but will reject if it doesn't.
// The resolution value will be the result of doSlowAsyncCalculation
return timeout(slowCalculationPromise, 5000);
}
*More info coming soon*