Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

when timeout

Trevor Senior edited this page · 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(5000, slowCalculationPromise);
}
Something went wrong with that request. Please try again.