summaryrefslogtreecommitdiff
path: root/node_modules/webworker-threads/test.ls
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/webworker-threads/test.ls')
-rwxr-xr-xnode_modules/webworker-threads/test.ls18
1 files changed, 18 insertions, 0 deletions
diff --git a/node_modules/webworker-threads/test.ls b/node_modules/webworker-threads/test.ls
new file mode 100755
index 0000000..a6610d0
--- /dev/null
+++ b/node_modules/webworker-threads/test.ls
@@ -0,0 +1,18 @@
+#!/usr/bin/env lsc
+{ Worker } = require \webworker-threads
+w = new Worker ->
+ # This also works, but less elegant:
+ # ``onmessage`` = (data: {max}) ->
+ @onmessage = (data: {max}) ->
+ :search for n from 2 to max
+ for i from 2 to Math.sqrt n
+ continue search unless n % i
+ postMessage { result: n }
+ throw \done
+w.onmessage = (data: {result}) ->
+ console.log "#result is a prime"
+w.onerror = ({data}) ->
+ console.log "Caught:", data
+ <~ setTimeout _, 100ms
+ @terminate!
+w.postMessage max: 100