Sha256: 4cfd33ba05c3f5a6d210cfefa3a08ce46864469686d32af047b1a0f610323218

Contents?: true

Size: 1.38 KB

Versions: 17

Compression:

Stored size: 1.38 KB

Contents

var to_array = require("./to_array");

// 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

17 entries across 17 versions & 2 rubygems

Version Path
hooch-0.4.2 jasmine/node_modules/karma/node_modules/socket.io/node_modules/redis/lib/queue.js
hooch-0.4.1 jasmine/node_modules/karma/node_modules/socket.io/node_modules/redis/lib/queue.js
hooch-0.4.0 jasmine/node_modules/karma/node_modules/socket.io/node_modules/redis/lib/queue.js
hooch-0.3.0 jasmine/node_modules/karma/node_modules/socket.io/node_modules/redis/lib/queue.js
hooch-0.2.1 jasmine/node_modules/karma/node_modules/socket.io/node_modules/redis/lib/queue.js
hooch-0.2.0 jasmine/node_modules/karma/node_modules/socket.io/node_modules/redis/lib/queue.js
hooch-0.1.0 jasmine/node_modules/karma/node_modules/socket.io/node_modules/redis/lib/queue.js
hooch-0.0.8 jasmine/node_modules/karma/node_modules/socket.io/node_modules/redis/lib/queue.js
hooch-0.0.7 jasmine/node_modules/karma/node_modules/socket.io/node_modules/redis/lib/queue.js
hooch-0.0.6 jasmine/node_modules/karma/node_modules/socket.io/node_modules/redis/lib/queue.js
entangled-0.0.16 spec/dummy/public/node_modules/karma/node_modules/socket.io/node_modules/redis/lib/queue.js
entangled-0.0.15 spec/dummy/public/node_modules/karma/node_modules/socket.io/node_modules/redis/lib/queue.js
entangled-0.0.14 spec/dummy/public/node_modules/karma/node_modules/socket.io/node_modules/redis/lib/queue.js
entangled-0.0.13 spec/dummy/public/node_modules/karma/node_modules/socket.io/node_modules/redis/lib/queue.js
entangled-0.0.12 spec/dummy/public/node_modules/karma/node_modules/socket.io/node_modules/redis/lib/queue.js
entangled-0.0.11 spec/dummy/public/node_modules/karma/node_modules/socket.io/node_modules/redis/lib/queue.js
entangled-0.0.10 spec/dummy/public/node_modules/karma/node_modules/socket.io/node_modules/redis/lib/queue.js