-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SQUASHED: AUTO-COMMIT-demos-worker-index.md,AUTO-COMMIT-demos-worker-sum-client.js,AUTO-COMMIT-demos-worker-sum.js,AUTO-COMMIT-demos-worker-sum-systemjs-client.js,AUTO-COMMIT-demos-worker-sum-systemjs-worker.js,AUTO-COMMIT-demos-worker-sum-worker.js,AUTO-COMMIT-doc-figures-worker.drawio,
- Loading branch information
1 parent
5658004
commit f8b7e2e
Showing
6 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Web Worker in Lively4 | ||
|
||
Worker, worker, worker... and which one is the real worker? | ||
|
||
Problem: There are too many modules in Lively4 that have "worker" in the name, can we change this? Are they all needed? How do they work together? | ||
|
||
<script> | ||
// setup | ||
async function fileEditor(fileName) { | ||
let editor = await (<lively-editor></lively-editor>) | ||
editor.setURL(lively4url + fileName) | ||
editor.loadFile() | ||
return editor | ||
} | ||
"" | ||
</script> | ||
|
||
## Classic Webworker | ||
|
||
|
||
### Client Code | ||
|
||
|
||
<script>fileEditor("/demos/worker/sum-client.js")</script> | ||
|
||
### Worker | ||
|
||
<script>fileEditor("/demos/worker/sum-worker.js")</script> | ||
|
||
## SystemJS Worker | ||
|
||
Since we are not in Kansas any more... we have no lively or systemjs on the worker side (yet). | ||
|
||
### Client code | ||
|
||
|
||
<script>fileEditor("/demos/worker/sum-systemjs-client.js")</script> | ||
|
||
### Worker | ||
|
||
<script>fileEditor("/demos/worker/sum-systemjs-worker.js")</script> | ||
|
||
|
||
## Hide onmessage and postMessage | ||
|
||
In <edit://src/babylonian-programming-editor/worker/babylonian-manager.js> and it's worker <edit://src/babylonian-programming-editor/worker/babylonian-worker.js>, the actual webworker is hidden with a promised method call... | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
var myworker = new Worker(lively4url + "/demos/worker/sum-worker.js") | ||
|
||
myworker.onmessage = function(evt) { | ||
lively.notify("sum = " + evt.data) | ||
} | ||
|
||
myworker.postMessage([3, 4]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import SystemjsWorker from "src/worker/systemjs-worker.js" | ||
|
||
var myworker = new SystemjsWorker(lively4url + "/demos/worker/sum-systemjs-worker.js") | ||
|
||
myworker.onmessage = function(evt) { | ||
lively.notify("sum = " + evt.data) | ||
} | ||
|
||
myworker.postMessage([3, 4]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import {sum} from "./sum.js" | ||
|
||
export function onmessage(e) { | ||
postMessage(sum(e.data)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
onmessage = function(e) { | ||
var array = e.data | ||
var sum = 0 | ||
for(let ea of array) { | ||
sum += ea | ||
} | ||
postMessage(sum); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
export function sum(array) { | ||
var sum = 0 | ||
for(let ea of array) { | ||
sum += ea | ||
} | ||
return sum | ||
} |