-
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.
new request mechanic for systemjs workers
SQUASHED: AUTO-COMMIT-demos-worker-sum-systemjs-worker.js,AUTO-COMMIT-src-worker-meta-worker.js,AUTO-COMMIT-src-worker-systemjs-worker.js,AUTO-COMMIT-test-systemjs-worker-test.js,AUTO-COMMIT-test-systemjs-worker-test-sum-worker.js,AUTO-COMMIT-test-systemjs-worker-test-worker.js,AUTO-COMMIT-test-worker-systemjs-worker-test.js,AUTO-COMMIT-test-worker-systemjs-worker-test-sum-request-worker.js,AUTO-COMMIT-test-worker-systemjs-worker-test-sum-response-worker.js,AUTO-COMMIT-test-worker-systemjs-worker-test-sum-worker.js,
- Loading branch information
1 parent
f8b7e2e
commit adc4cc8
Showing
6 changed files
with
157 additions
and
9 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 |
---|---|---|
|
@@ -2,4 +2,7 @@ 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
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
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,26 @@ | ||
|
||
|
||
|
||
export async function onrequest(msg) { | ||
if (msg.name === "sum") { | ||
var array = msg.arguments | ||
let result = array[0] + array[1] | ||
|
||
return result | ||
} | ||
throw new Error("request not understood: " + msg) | ||
} | ||
|
||
|
||
// export function onmessage(evt) { | ||
// if(evt.data && evt.data.message === "systemjs-worker-request") { | ||
// if (evt.data.name === "sum") { | ||
// var array = evt.data.arguments | ||
// let result = array[0] + array[1] | ||
// // console.log("ON MESSAGE result " + result) | ||
// return postMessage({message: "systemjs-worker-response", name: evt.data.name, id: evt.data.id, response: result}) | ||
// } | ||
// return postMessage({error: "unhandled systemjs-worker-request " + evt}) | ||
// } | ||
// return postMessage({error: "could not handle message " + evt}) | ||
// } |
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,7 @@ | ||
|
||
|
||
export function onmessage(evt) { | ||
let result = evt.data[0] + evt.data[1] | ||
|
||
postMessage(result) | ||
} |
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,54 @@ | ||
|
||
import SystemjsWorker from "src/worker/systemjs-worker.js" | ||
|
||
import {expect} from 'src/external/chai.js'; | ||
|
||
describe('SystemJSWorker', () => { | ||
|
||
|
||
describe('onmessage and postMessage', () => { | ||
let myworker | ||
before(async () => { | ||
myworker = new SystemjsWorker(lively4url + "/test/worker/systemjs-worker-test-sum-worker.js") | ||
|
||
await myworker.loaded | ||
}) | ||
|
||
it('sums', async () => { | ||
var wasrun = false | ||
myworker.onmessage = (evt) => { | ||
wasrun = true | ||
expect(evt.data).equals(7) | ||
} | ||
myworker.postMessage([3, 4]); | ||
|
||
await lively.sleep(1) // not directly connected yet | ||
|
||
expect(wasrun, "wasrun").equals(true) | ||
|
||
}) | ||
after(() => { | ||
myworker.terminate() | ||
}) | ||
|
||
}) | ||
|
||
describe('request', () => { | ||
let myworker | ||
before(async () => { | ||
myworker = new SystemjsWorker(lively4url + "/test/worker/systemjs-worker-test-sum-request-worker.js") | ||
|
||
await myworker.loaded | ||
}) | ||
|
||
it('sums', async () => { | ||
|
||
var result = await myworker.request("sum", [3, 4]); | ||
|
||
// expect(result, "result").equals(7) | ||
}) | ||
after(() => { | ||
myworker.terminate() | ||
}) | ||
}) | ||
}); |