Sha256: e57083c8bd75e769535cc21d47a14e284721c6ddc77ddf99be0f85708ee1cf76

Contents?: true

Size: 1.03 KB

Versions: 14

Compression:

Stored size: 1.03 KB

Contents

var utils = require('./utils')

function Batcher () {
    this.reset()
}

var BatcherProto = Batcher.prototype

BatcherProto.push = function (job) {
    if (!job.id || !this.has[job.id]) {
        this.queue.push(job)
        this.has[job.id] = job
        if (!this.waiting) {
            this.waiting = true
            utils.nextTick(utils.bind(this.flush, this))
        }
    } else if (job.override) {
        var oldJob = this.has[job.id]
        oldJob.cancelled = true
        this.queue.push(job)
        this.has[job.id] = job
    }
}

BatcherProto.flush = function () {
    // before flush hook
    if (this._preFlush) this._preFlush()
    // do not cache length because more jobs might be pushed
    // as we execute existing jobs
    for (var i = 0; i < this.queue.length; i++) {
        var job = this.queue[i]
        if (!job.cancelled) {
            job.execute()
        }
    }
    this.reset()
}

BatcherProto.reset = function () {
    this.has = utils.hash()
    this.queue = []
    this.waiting = false
}

module.exports = Batcher

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
fluentd-ui-0.3.8 vendor/assets/javascripts/bower/vue/src/batcher.js
fluentd-ui-0.3.7 vendor/assets/javascripts/bower/vue/src/batcher.js
fluentd-ui-0.3.6 vendor/assets/javascripts/bower/vue/src/batcher.js
fluentd-ui-0.3.5 vendor/assets/javascripts/bower/vue/src/batcher.js
fluentd-ui-0.3.3 vendor/assets/javascripts/bower/vue/src/batcher.js
fluentd-ui-0.3.2 vendor/assets/javascripts/bower/vue/src/batcher.js
fluentd-ui-0.3.1 vendor/assets/javascripts/bower/vue/src/batcher.js
fluentd-ui-0.3.0 vendor/assets/javascripts/bower/vue/src/batcher.js
fluentd-ui-0.2.0 vendor/assets/javascripts/bower/vue/src/batcher.js
fluentd-ui-0.1.4 vendor/assets/javascripts/bower/vue/src/batcher.js
fluentd-ui-0.1.3 vendor/assets/javascripts/bower/vue/src/batcher.js
fluentd-ui-0.1.2 vendor/assets/javascripts/bower/vue/src/batcher.js
fluentd-ui-0.1.1 vendor/assets/javascripts/bower/vue/src/batcher.js
fluentd-ui-0.1.0 vendor/assets/javascripts/bower/vue/src/batcher.js