Code coverage report for debug\async.js

Statements: 94.74% (72 / 76)      Branches: 88.24% (15 / 17)      Functions: 93.75% (15 / 16)      Lines: 94.52% (69 / 73)      Ignored: none     

All files » debug\ » async.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120  8 8 8 8 8 8   8 8 8 8 8 8 8192   8       8 2     8 13961   13961     3   13961     8 17 14 14   17 17 17 17                     8 3030   3030 3030 3030     8 3   3 3 3     8 10911   10911 10911 10911     8 16125 16125     8 16384 30069 30069 16125 16125   13944 13944 13944       8 8192   8192 8192 8192     8 30069 8192 8192       8 8192     8 8      
(function () { "use strict";
var firstLineError;
try {throw new Error(); } catch (e) {firstLineError = e;}
var ASSERT = require("./assert.js");
var schedule = require("./schedule.js");
var Queue = require("./queue.js");
var _process = typeof process !== "undefined" ? process : undefined;
 
function Async() {
    this._isTickUsed = false;
    this._lateQueue = new Queue(16);
    this._normalQueue = new Queue(16);
    var self = this;
    this.drainQueues = function () {
        self._drainQueues();
    };
    this._schedule =
        schedule.isStatic ? schedule(this.drainQueues) : schedule;
}
 
Async.prototype.haveItemsQueued = function () {
    return this._normalQueue.length() > 0;
};
 
Async.prototype._withDomain = function(fn) {
    ASSERT(((typeof fn) === "function"),
    "typeof fn === \u0022function\u0022");
    if (_process !== undefined &&
        _process.domain != null &&
        !fn.domain) {
        fn = _process.domain.bind(fn);
    }
    return fn;
};
 
Async.prototype.throwLater = function(fn, arg) {
    if (arguments.length === 1) {
        arg = fn;
        fn = function () { throw arg; };
    }
    fn = this._withDomain(fn);
    Eif (typeof setTimeout !== "undefined") {
        setTimeout(function() {
            fn(arg);
        }, 0);
    } else try {
        this._schedule(function() {
            fn(arg);
        });
    } catch (e) {
        throw new Error("No async scheduler available\u000a\u000a    See http://goo.gl/m3OTXk\u000a");
    }
};
 
Async.prototype.invokeLater = function (fn, receiver, arg) {
    ASSERT((arguments.length === 3),
    "arguments.length === 3");
    fn = this._withDomain(fn);
    this._lateQueue.push(fn, receiver, arg);
    this._queueTick();
};
 
Async.prototype.invokeFirst = function (fn, receiver, arg) {
    ASSERT((arguments.length === 3),
    "arguments.length === 3");
    fn = this._withDomain(fn);
    this._normalQueue.unshift(fn, receiver, arg);
    this._queueTick();
};
 
Async.prototype.invoke = function (fn, receiver, arg) {
    ASSERT((arguments.length === 3),
    "arguments.length === 3");
    fn = this._withDomain(fn);
    this._normalQueue.push(fn, receiver, arg);
    this._queueTick();
};
 
Async.prototype.settlePromises = function(promise) {
    this._normalQueue._pushOne(promise);
    this._queueTick();
};
 
Async.prototype._drainQueue = function(queue) {
    while (queue.length() > 0) {
        var fn = queue.shift();
        if (typeof fn !== "function") {
            fn._settlePromises();
            continue;
        }
        var receiver = queue.shift();
        var arg = queue.shift();
        fn.call(receiver, arg);
    }
};
 
Async.prototype._drainQueues = function () {
    ASSERT(this._isTickUsed,
    "this._isTickUsed");
    this._drainQueue(this._normalQueue);
    this._reset();
    this._drainQueue(this._lateQueue);
};
 
Async.prototype._queueTick = function () {
    if (!this._isTickUsed) {
        this._isTickUsed = true;
        this._schedule(this.drainQueues);
    }
};
 
Async.prototype._reset = function () {
    this._isTickUsed = false;
};
 
module.exports = new Async();
module.exports.firstLineError = firstLineError;
 
}());