lib/backpack/index.js
function (callback, ms, scope, when) {
        ms = Number(ms);

        // if np callback time is specified, just return the callback function and exit. this is because we do need to
        // track timeout in 0ms
        if (!ms) {
            return callback;
        }

        var sealed = false,
            irq = setTimeout(function () { // irq = interrupt request
                sealed = true;
                irq = null;
                when && when.call(scope || this);
                callback.call(scope || this, new Error('callback timed out'));
            }, ms);

        return function () {
            // if sealed, it means that timeout has elapsed and we accept no future callback
            if (sealed) { return undefined; }

            // otherwise we clear timeout and allow the callback to be executed. note that we do not seal the function
            // since we should allow multiple callback calls.
            irq && (irq = clearTimeout(irq));

            return callback.apply(scope || this, arguments);
        };
    }
function (callback, ms, scope, when) {
        ms = Number(ms);

        // if np callback time is specified, just return the callback function and exit. this is because we do need to
        // track timeout in 0ms
        if (!ms) {
            return callback;
        }

        var sealed = false,
            irq = setTimeout(function () { // irq = interrupt request
                sealed = true;
                irq = null;
                when && when.call(scope || this);
                callback.call(scope || this, new Error('callback timed out'));
            }, ms);

        return function () {
            // if sealed, it means that timeout has elapsed and we accept no future callback
            if (sealed) { return undefined; }

            // otherwise we clear timeout and allow the callback to be executed. note that we do not seal the function
            // since we should allow multiple callback calls.
            irq && (irq = clearTimeout(irq));

            return callback.apply(scope || this, arguments);
        };
    }
function ( callback , ms , scope , when ) { ms = Number ( ms ) ; // if np callback time is specified, just return the callback function and exit. this is because we do need to // track timeout in 0ms if ( ! ms ) { return callback ; } var sealed = false , irq = setTimeout ( function ( ) { // irq = interrupt request sealed = true ; irq = null ; when && when . call ( scope || this ) ; callback . call ( scope || this , new Error ( 'callback timed out' ) ) ; } , ms ) ; return function ( ) { // if sealed, it means that timeout has elapsed and we accept no future callback if ( sealed ) { return undefined ; } // otherwise we clear timeout and allow the callback to be executed. note that we do not seal the function // since we should allow multiple callback calls. irq && ( irq = clearTimeout ( irq ) ) ; return callback . apply ( scope || this , arguments ) ; } ; }
Ensures that a callback is executed within a specific time.

@param {Function} callback
@param {Number=} [ms]
@param {Object=} [scope]
@param {Function=} [when] - function executed right before callback is called with timeout. one can do cleanup
stuff here
@returns {Function}
Ensures that a callback is executed within a specific time .