Sha256: 79fc3f22c3ff5da3cdfb521419fde0553b07d5d9be8c06c737b9ba2e27c7120a

Contents?: true

Size: 1.35 KB

Versions: 15

Compression:

Stored size: 1.35 KB

Contents

// Queue class adapted from Tim Caswell's pattern library
// http://github.com/creationix/pattern/blob/master/lib/pattern/queue.js

function Queue() {
    this.tail = [];
    this.head = [];
    this.offset = 0;
}

Queue.prototype.shift = function () {
    if (this.offset === this.head.length) {
        var tmp = this.head;
        tmp.length = 0;
        this.head = this.tail;
        this.tail = tmp;
        this.offset = 0;
        if (this.head.length === 0) {
            return;
        }
    }
    return this.head[this.offset++]; // sorry, JSLint
};

Queue.prototype.push = function (item) {
    return this.tail.push(item);
};

Queue.prototype.forEach = function (fn, thisv) {
    var array = this.head.slice(this.offset), i, il;

    array.push.apply(array, this.tail);

    if (thisv) {
        for (i = 0, il = array.length; i < il; i += 1) {
            fn.call(thisv, array[i], i, array);
        }
    } else {
        for (i = 0, il = array.length; i < il; i += 1) {
            fn(array[i], i, array);
        }
    }

    return array;
};

Queue.prototype.getLength = function () {
    return this.head.length - this.offset + this.tail.length;
};
    
Object.defineProperty(Queue.prototype, "length", {
    get: function () {
        return this.getLength();
    }
});


if (typeof module !== "undefined" && module.exports) {
    module.exports = Queue;
}

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
express_translate-1.0.13 node_modules/redis/lib/queue.js
express_translate-1.0.12 node_modules/redis/lib/queue.js
express_translate-1.0.11 node_modules/redis/lib/queue.js
express_translate-1.0.10 node_modules/redis/lib/queue.js
express_translate-1.0.9 node_modules/redis/lib/queue.js
express_translate-1.0.8 node_modules/redis/lib/queue.js
express_translate-1.0.7 node_modules/redis/lib/queue.js
express_translate-1.0.6 node_modules/redis/lib/queue.js
express_translate-1.0.5 node_modules/redis/lib/queue.js
express_translate-1.0.4 node_modules/redis/lib/queue.js
express_translate-1.0.3 node_modules/redis/lib/queue.js
express_translate-1.0.2 node_modules/redis/lib/queue.js
express_translate-1.0.1 node_modules/redis/lib/queue.js
express_translate-1.0 node_modules/redis/lib/queue.js
express_translate-1.0.0.0 node_modules/redis/lib/queue.js