summaryrefslogtreecommitdiff
path: root/node_modules/webworker-threads/src/events.ls
diff options
context:
space:
mode:
authoryo mama <pepper@scannerjammer.com>2015-04-04 01:00:59 -0700
committeryo mama <pepper@scannerjammer.com>2015-04-04 01:00:59 -0700
commitc7c22e3db1c826bcfb2bc66651ec480aae0d4ae0 (patch)
tree8546df448afef40d3814d2581f4dacff7cebb87f /node_modules/webworker-threads/src/events.ls
Diffstat (limited to 'node_modules/webworker-threads/src/events.ls')
-rw-r--r--node_modules/webworker-threads/src/events.ls29
1 files changed, 29 insertions, 0 deletions
diff --git a/node_modules/webworker-threads/src/events.ls b/node_modules/webworker-threads/src/events.ls
new file mode 100644
index 0000000..4e604b7
--- /dev/null
+++ b/node_modules/webworker-threads/src/events.ls
@@ -0,0 +1,29 @@
+function DispatchEvents (thread)
+ thread = this <<< {
+ on: (e, f, q) ->
+ if q = thread._on[e] then q.push f else thread._on[e] = [f]
+ return thread
+ once: (e, f, q) ->
+ not (q = thread._on[e]) and (q = thread._on[e] = [])
+ if q.once then q.once.push f else q.once = [f]
+ return thread
+ remove-all-listeners: (e) ->
+ if arguments_.length then delete! thread._on[e] else thread._on = {}
+ return thread
+ dispatch-events: (event, args, q, i, len) ->
+ 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
+ q[i++].apply thread, args
+ catch
+ __postError { message: e, filename: '', lineno: 0 }
+ _on: {}
+ }
+ return @dispatch-events