Skip to content

Commit

Permalink
Unclutter API, allow sending intermediate messages to Worker
Browse files Browse the repository at this point in the history
  • Loading branch information
kaisalmen committed Oct 4, 2023
1 parent 5977e80 commit 75c2c35
Show file tree
Hide file tree
Showing 23 changed files with 192 additions and 191 deletions.
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,9 @@ workerTaskDirector.registerTask(taskName, {
try {
await workerTaskDirector.initTaskType(taskName)
// once the init Promise returns enqueue the execution
const execMessage = new WorkerTaskMessage({
id: 0,
name: taskName
});
const execMessage = new WorkerTaskMessage();

await workerTaskDirector.enqueueWorkerExecutionPlan({
taskTypeName: execMessage.name,
await workerTaskDirector.enqueueWorkerExecutionPlan(taskName, {
message: execMessage,
// decouple result evaluation ...
onComplete: (m: WorkerTaskMessageType) => { console.log('Received final command: ' + m.cmd); }
Expand Down
146 changes: 78 additions & 68 deletions package-lock.json

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

7 changes: 3 additions & 4 deletions packages/examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@
"preview": "http-server ./preview"
},
"dependencies": {
"lil-gui": "~0.17.0",
"wtd-core": "2.2.0",
"wtd-three-ext": "2.2.0",
"wwobjloader2": "5.1.0-next.0"
"lil-gui": "~0.18.2",
"wtd-three-ext": "2.2.1-next.0",
"wwobjloader2": "~6.0.1"
},
"devDependencies": {
"http-server": "~14.1.1"
Expand Down
8 changes: 2 additions & 6 deletions packages/examples/src/helloWorld/HelloWorld.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,8 @@ class HelloWorldModuleWorkerExample {

const t0 = performance.now();
// once the init Promise returns enqueue the execution
const execMessage = new WorkerTaskMessage({
id: 0,
name: taskName
});
const resultExec = await this.workerTaskDirector.enqueueWorkerExecutionPlan({
taskTypeName: execMessage.name,
const execMessage = new WorkerTaskMessage();
const resultExec = await this.workerTaskDirector.enqueueWorkerExecutionPlan(taskName, {
message: execMessage,
// decouple result evaluation ...
onComplete: (m: WorkerTaskMessageType) => {
Expand Down
8 changes: 2 additions & 6 deletions packages/examples/src/helloWorld/HelloWorldStandard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,8 @@ class HelloWorldStandardWorkerExample {

const t0 = performance.now();
// once the init Promise returns enqueue the execution
const execMessage = new WorkerTaskMessage({
id: 0,
name: taskName
});
const resultExec = await this.workerTaskDirector.enqueueWorkerExecutionPlan({
taskTypeName: execMessage.name,
const execMessage = new WorkerTaskMessage();
const resultExec = await this.workerTaskDirector.enqueueWorkerExecutionPlan(taskName, {
message: execMessage,
// decouple result evaluation ...
onComplete: (m: WorkerTaskMessageType) => {
Expand Down
12 changes: 2 additions & 10 deletions packages/examples/src/helloWorld/HelloWorldWorkerTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ class HelloWorldWorkerTaskExample {
url: new URL(import.meta.env.DEV ? '../worker/HelloWorldWorker.ts' : '../worker/generated/HelloWorldWorker-es.js', import.meta.url)
}, true);

const initMessage = new WorkerTaskMessage({
cmd: 'init',
id: 0,
name: taskName
});
const initMessage = new WorkerTaskMessage();

try {
// init the worker task without any payload (worker init without function invocation on worker)
Expand All @@ -31,12 +27,8 @@ class HelloWorldWorkerTaskExample {

const t0 = performance.now();
// once the init Promise returns enqueue the execution
const execMessage = new WorkerTaskMessage({
id: 0,
name: taskName
});
const execMessage = new WorkerTaskMessage();
const resultExec = await workerTask.executeWorker({
taskTypeName: execMessage.name,
message: execMessage,
// decouple result evaluation ...
onComplete: (m: WorkerTaskMessageType) => {
Expand Down
3 changes: 1 addition & 2 deletions packages/examples/src/threejs/Threejs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ class WorkerTaskDirectorExample {
name: `${name}_${globalCount}`
});

const voidPromise = this.workerTaskDirector.enqueueWorkerExecutionPlan({
taskTypeName: name ?? 'unknown',
const voidPromise = this.workerTaskDirector.enqueueWorkerExecutionPlan(name ?? 'unknown', {
message: execMessage,
onComplete: (m: WorkerTaskMessageType) => {
this.processMessage(m);
Expand Down
3 changes: 1 addition & 2 deletions packages/examples/src/transferables/TransferablesTestbed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,8 @@ class TransferablesTestbed {
execMessage.addPayload(dataPayload);
const transferables = execMessage.pack(false);

return this.workerTaskDirector.enqueueWorkerExecutionPlan({
return this.workerTaskDirector.enqueueWorkerExecutionPlan(task.name, {
message: execMessage,
taskTypeName: task.name,
onComplete: (m: WorkerTaskMessageType) => {
this.processMessage(m);
},
Expand Down
5 changes: 2 additions & 3 deletions packages/examples/src/worker/HelloWorldThreeWorker.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { SphereGeometry } from 'three';
import {
WorkerTaskDirectorDefaultWorker,
WorkerTaskDirectorWorker,
WorkerTaskDefaultWorker,
WorkerTaskMessage,
WorkerTaskMessageType
} from 'wtd-core';
Expand All @@ -11,7 +10,7 @@ import {

declare const self: DedicatedWorkerGlobalScope;

export class HelloWorlThreedWorker extends WorkerTaskDirectorDefaultWorker implements WorkerTaskDirectorWorker {
export class HelloWorlThreedWorker extends WorkerTaskDefaultWorker {

init(message: WorkerTaskMessageType) {
console.log(`HelloWorldWorker#init: name: ${message.name} id: ${message.id} cmd: ${message.cmd} workerId: ${message.workerId}`);
Expand Down
5 changes: 2 additions & 3 deletions packages/examples/src/worker/HelloWorldWorker.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import {
DataPayload,
WorkerTaskDirectorDefaultWorker,
WorkerTaskDirectorWorker,
WorkerTaskDefaultWorker,
WorkerTaskMessage,
WorkerTaskMessageType
} from 'wtd-core';

declare const self: DedicatedWorkerGlobalScope;

export class HelloWorldWorker extends WorkerTaskDirectorDefaultWorker implements WorkerTaskDirectorWorker {
export class HelloWorldWorker extends WorkerTaskDefaultWorker {

init(message: WorkerTaskMessageType) {
const initComplete = WorkerTaskMessage.createFromExisting(message, 'initComplete');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import {
BufferGeometry
} from 'three';
import {
WorkerTaskDirectorDefaultWorker,
WorkerTaskDirectorWorker,
WorkerTaskDefaultWorker,
WorkerTaskMessage,
WorkerTaskMessageType
} from 'wtd-core';
Expand All @@ -13,7 +12,7 @@ import {

declare const self: DedicatedWorkerGlobalScope;

class InfiniteWorkerExternalGeometry extends WorkerTaskDirectorDefaultWorker implements WorkerTaskDirectorWorker {
class InfiniteWorkerExternalGeometry extends WorkerTaskDefaultWorker {

private localData = {
meshPayloadRaw: undefined as MeshPayloadType | undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import {
MeshPhongMaterial
} from 'three';
import {
WorkerTaskDirectorDefaultWorker,
WorkerTaskDirectorWorker,
WorkerTaskDefaultWorker,
WorkerTaskMessage,
WorkerTaskMessageType
} from 'wtd-core';
Expand All @@ -15,7 +14,7 @@ import {
MaterialsPayload,
} from 'wtd-three-ext';

class InfiniteWorkerInternalGeometry extends WorkerTaskDirectorDefaultWorker implements WorkerTaskDirectorWorker {
class InfiniteWorkerInternalGeometry extends WorkerTaskDefaultWorker {

init(message: WorkerTaskMessageType) {
const initComplete = WorkerTaskMessage.createFromExisting(message, 'initComplete');
Expand Down
Loading

0 comments on commit 75c2c35

Please sign in to comment.