summaryrefslogtreecommitdiff
path: root/node_modules/webworker-threads/src/thread_nextTick.js
blob: e8cf3c00e39b982b95b484bbec607047db465ab7 (plain)
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
function ThreadNextTick(){
  function nextTick(cb){
    thread._ntq.push(cb);
    return this;
  }
  function dispatchNextTicks(l, p, err, _ntq){
    var e;
    if (l = (_ntq = thread._ntq).length) {
      p = err = 0;
      try {
        for (;;) {
          _ntq[p]();
          if (!(++p < l)) {
            break;
          }
        }
      } catch (e$) {
        e = e$;
        thread._ntq = _ntq.slice(++p);
        throw e;
      }
      return (thread._ntq = _ntq.slice(p)).length;
    }
    return 0;
  }
  thread._ntq = [];
  thread.nextTick = nextTick;
  return dispatchNextTicks;
}