summaryrefslogtreecommitdiff
path: root/node_modules/webworker-threads/src/events.js
blob: b38a30ec1a937f052b25ba85988fee35c6982954 (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
function DispatchEvents(thread){
  thread = (this.on = function(e, f, q){
    if (q = thread._on[e]) {
      q.push(f);
    } else {
      thread._on[e] = [f];
    }
    return thread;
  }, this.once = function(e, f, q){
    !(q = thread._on[e]) && (q = thread._on[e] = []);
    if (q.once) {
      q.once.push(f);
    } else {
      q.once = [f];
    }
    return thread;
  }, this.removeAllListeners = function(e){
    if (arguments_.length) {
      delete thread._on[e];
    } else {
      thread._on = {};
    }
    return thread;
  }, this.dispatchEvents = function(event, args, q, i, len){
    var e, results$ = [];
    if (q = thread._on[event]) {
      try {
        i = 0;
        len = q.length;
        while (i < len) {
          q[i++].apply(thread, args);
        }
        if (q = q.once) {
          q.once = undefined;
          i = 0;
          len = q.length;
          while (i < len) {
            results$.push(q[i++].apply(thread, args));
          }
          return results$;
        }
      } catch (e$) {
        e = e$;
        return __postError({
          message: e,
          filename: '',
          lineno: 0
        });
      }
    }
  }, this._on = {}, this);
  return this.dispatchEvents;
}