Skip to content

Commit

Permalink
Separate Payload, RawPayload and DataPayload
Browse files Browse the repository at this point in the history
- All payloads have message parameter
- Remove the need for static functions
  • Loading branch information
kaisalmen committed Oct 22, 2023
1 parent 3140ec2 commit 50a93f6
Show file tree
Hide file tree
Showing 33 changed files with 640 additions and 542 deletions.
24 changes: 5 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ <h1>WorkerTaskDirector: Examples</h1>
<br>
<a href="threejs.html">three.js Example</a>
<br>
<a href="potentially_infinite.html">Potentially Infinite Execution</a>
<br>
<!-- <a href="potentially_infinite.html">Potentially Infinite Execution</a>
<br> -->
</div>

</body>
Expand Down
8 changes: 4 additions & 4 deletions packages/examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"build:worker:TransferableWorkerTest3": "shx rm -f ./src/worker/generated/TransferableWorkerTest3*.js && vite -c build/vite.config.TransferableWorkerTest3.ts build",
"build:worker:TransferableWorkerTest4": "shx rm -f ./src/worker/generated/TransferableWorkerTest4*.js && vite -c build/vite.config.TransferableWorkerTest4.ts build",
"build:worker": "npm run build:worker:HelloWorldWorker && npm run build:worker:Com1Worker && npm run build:worker:Com2Worker && npm run build:worker:HelloWorldThreeWorker && npm run build:worker:InfiniteWorkerExternalGeometry && npm run build:worker:InfiniteWorkerInternalGeometry && npm run build:worker:OBJLoaderWorker && npm run build:worker:TransferableWorkerTest1 && npm run build:worker:TransferableWorkerTest2 && npm run build:worker:TransferableWorkerTest3 && npm run build:worker:TransferableWorkerTest4",
"build": "npm run clean && npm run copy:worker:OBJLoader2Worker && npm run compile",
"_build": "npm run clean && npm run copy:worker:OBJLoader2Worker && npm run compile",
"build": "npm run clean && npm run compile",
"clean:production": "shx rm -fr preview",
"copy:assets:production": "shx mkdir -p ./preview/worker/generated && shx cp -f ./src/worker/generated/*.js ./preview/worker/generated && shx cp -f ./models/obj/female02/*.jpg ./preview/assets",
"build:production": "npm run build && npm run build:worker && npm run build:production:vite",
Expand All @@ -29,9 +30,8 @@
},
"dependencies": {
"lil-gui": "~0.18.2",
"wtd-core": "~2.3.0",
"wtd-three-ext": "~2.3.0",
"wwobjloader2": "~6.1.0"
"wtd-core": "~2.4.0-next.0",
"wtd-three-ext": "~2.4.0-next.0"
},
"devDependencies": {
"http-server": "~14.1.1"
Expand Down
6 changes: 3 additions & 3 deletions packages/examples/src/com/WorkerCom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ class HelloWorldStandardWorkerExample {

const execCom1 = new WorkerTaskMessage();
const payload1 = new RawPayload();
payload1.message = { port: channel.port1 };
payload1.message.raw = { port: channel.port1 };
execCom1.addPayload(payload1);

const execCom2 = new WorkerTaskMessage();
const payload2 = new RawPayload();
payload2.message = { port: channel.port2 };
payload2.message.raw = { port: channel.port2 };
execCom2.addPayload(payload2);

const onComplete = (message: WorkerTaskMessageType) => {
console.log('Received final command: ' + message.cmd);
const rawPayload = message.payloads[0] as RawPayload;
console.log(`Worker said onComplete: ${rawPayload.message.hello}`);
console.log(`Worker said onComplete: ${rawPayload.message.raw.hello}`);
};

const resultExecCom1 = workerTaskCom1.executeWorker({
Expand Down
5 changes: 3 additions & 2 deletions packages/examples/src/helloWorld/HelloWorld.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {
WorkerTaskDirector,
WorkerTaskMessage,
WorkerTaskMessageType
WorkerTaskMessageType,
unpack
} from 'wtd-core';

/**
Expand Down Expand Up @@ -36,7 +37,7 @@ class HelloWorldModuleWorkerExample {
message: execMessage,
// decouple result evaluation ...
onComplete: (m: WorkerTaskMessageType) => {
const wtm = WorkerTaskMessage.unpack(m, false);
const wtm = unpack(m, false);
console.log(wtm);
if (wtm.payloads.length === 1) {
console.log(wtm.payloads[0]);
Expand Down
5 changes: 3 additions & 2 deletions packages/examples/src/helloWorld/HelloWorldWorkerTask.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {
WorkerTask,
WorkerTaskMessage,
WorkerTaskMessageType
WorkerTaskMessageType,
unpack
} from 'wtd-core';

/**
Expand Down Expand Up @@ -32,7 +33,7 @@ class HelloWorldWorkerTaskExample {
message: execMessage,
// decouple result evaluation ...
onComplete: (m: WorkerTaskMessageType) => {
const wtm = WorkerTaskMessage.unpack(m, false);
const wtm = unpack(m, false);
console.log(wtm);
if (wtm.payloads.length === 1) {
console.log(wtm.payloads[0]);
Expand Down
Loading

0 comments on commit 50a93f6

Please sign in to comment.