Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/utils/platforms/browser/lib/reactor.js
blob: bd0f10cfa3a06a3a1ce3d0ace73de9f91c8d6b4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

var active = false;
var pending = [];
var run = function () {
    var task = pending.shift();
    if (0 === pending.length) {
        active = false;
    } else {
        setTimeout(run, 0);
    }
    task();
};

exports.enqueue = function enqueue(task) {
    pending.push(task);
    if (!active) {
        setTimeout(run, 0);
        active = true;
    }
};