Skip to content

Commit

Permalink
Updated READMEs, LICENSEs and CHANGELOGs. Renamed three-wtm to wtd wh…
Browse files Browse the repository at this point in the history
…ere not yet done
  • Loading branch information
kaisalmen committed Jan 4, 2024
1 parent 6eb9826 commit f703acd
Show file tree
Hide file tree
Showing 11 changed files with 158 additions and 77 deletions.
13 changes: 10 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
# Changelog

## 2.4.0 - 2023-10-2x

- Added `RawPayload` and new `WorkerCom` example that demonstrates inter-worker communication.
## 3.0.0 - 2023-12-2x

- Make the worker lifecylce no longer mandatory if not using `WorkerTaskDirector`.
- Sent message with or without awaiting them.
- `WorkerTask` keeps track of messages that need to be awaited.
- API clean-up and code improvements
- Use configuration objects instead of long number of arguments
- Added helper functions for creating an OffscreenCanvas and delegating events to the worker.
- Extracted `Payload` from `DataPayload` and created `RawPayload` for supporting plain messages.
- Added new example [Inter-Worker Communication](https://github.com/kaisalmen/wtd/blob/main/packages/examples/src/com/WorkerCom.ts) that demonstrates communication between workers utilizing message channels.

## 2.3.0 - 2023-10-21

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021-2022 Kai Salmen
Copyright (c) 2021-2024 Kai Salmen

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
50 changes: 33 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,52 @@
# WorkerTask, WorkerTaskDirector and three.js extensions

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/kaisalmen/three-wtm/blob/main/LICENSE)
[![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/kaisalmen/three-wtm)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/kaisalmen/wtd/blob/main/LICENSE)
[![wtd](https://github.com/kaisalmen/wtd/actions/workflows/actions.yml/badge.svg)](https://github.com/kaisalmen/wtd/actions/workflows/actions.yml)
[![Github Pages](https://img.shields.io/badge/GitHub-Pages-blue?logo=github)](https://kaisalmen.github.io/wtd)
[![wtd-core version](https://img.shields.io/npm/v/wtd-core?logo=npm&label=wtd-core)](https://www.npmjs.com/package/wtd-core)
[![wtd-three-ext version](https://img.shields.io/npm/v/wtd-three-ext?logo=npm&label=wtd-three-ext)](https://www.npmjs.com/package/wtd-three-ext)
[![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/kaisalmen/wtd)

Build applications with workers with less boiler plate code.

- [WorkerTask, WorkerTaskDirector and three.js extensions](#workertask-workertaskdirector-and-threejs-extensions)
- [Overview](#overview)
- [Examples](#examples)
- [Usage](#usage)
- [Getting Started](#getting-started)
- [WorkerTaskDirector Execution Workflow](#workertaskdirector-execution-workflow)
- [Main Branches](#main-branches)
- [Docs](#docs)
- [History](#history)

## Overview

- `wtd-core`:
- [wtd-core](https://www.npmjs.com/package/wtd-core) main features:
- `WorkerTask`: Defines a non-mandatory (**New with v3**) lifecycle and message protocol (`WorkerTaskMessage`) with optional `Payload` for using and re-using workers. Either use `init` and `execute` funtions to follow a basic lifecycle or send various message either awaiting feedback or not. Use a `WorkerTaskWorker` to connect your ESM worker code with the communication routing. `WorkerTask` ensures aynchronous feedback reaches the caller.
- `WorkerTaskManager`: Manages the execution of mutliple `WorkerTask` and multiple instances in parallel. It allows to queue tasks for later execution. This only works when the basic lifecycle is used.
- **New with v3**: Helper functions for creating an OffscreenCanvas and delegating events to the worker. It provides a default configuration, but allows to customize all aspects of the configuration to your specific needs. This work was inspired by [three.js optimization manual](https://threejs.org/manual/#en/offscreencanvas)
- `wtd-three-ext`:
- [wtd-three-ext](https://www.npmjs.com/package/wtd-three-ext) main features:
- [three.js](https://github.com/mrdoob/three.js) related extension. It allows to define/extend "enhanced" payloads useful in the context of three.js (e.g. exchange Mesh or Material data).
- **New with v3**: Extension to the OffscreenCanvas functions. It can trick the code running in the worker to think it has a real canvas allowing to re-use the exact same code. This work was also inspired by [three.js optimization manual](https://threejs.org/manual/#en/offscreencanvas)

## Examples

There are multiple examples available demonstarting the features described above (listed from simple to advanced):
There are multiple examples available demonstarting the features described above (listed from simpler to more advanced):

- **WorkerTask: Hello World**: [html](./packages/examples/helloWorldWorkerTask.html), [ts](./packages/examples/src/helloWorld/HelloWorldWorkerTask.ts), [worker](./packages/examples/src/worker/HelloWorldWorker.ts)
- **WorkerTaskDirector: Hello World**: [html](./packages/examples/helloWorldWorkerTaskDirector.html), [ts](./packages/examples/src/helloWorld/helloWorldWorkerTaskDirector.ts), [worker](./packages/examples/src/worker/HelloWorldWorker.ts)
- **WorkerTask: Inter-Worker Communication**: [html](./packages/examples/workerCom.html), [ts](./packages/examples/src/com/WorkerCom.ts), **Worker**: [1](./packages/examples/src/worker/Com1Worker.ts) and [2](./packages/examples/src/worker/Com2Worker.ts)
- **WorkerTaskDirector: Transferables**: [html](./packages/examples/transferables.html), [ts](./packages/examples/src/transferables/TransferablesTestbed.ts), **Worker**: [1](./packages/examples/src/worker/TransferableWorkerTest1.ts), [2](./packages/examples/src/worker/TransferableWorkerTest2.ts), [3](./packages/examples/src/worker/TransferableWorkerTest3.ts), [4](./packages/examples/src/worker/TransferableWorkerTest4.ts)
- **WorkerTaskDirector: Three.js**: [html](./packages/examples/threejs.html), [ts](./packages/examples/src/threejs/Threejs.ts), **Worker**: [1](./packages/examples/src/worker/HelloWorldThreeWorker.ts), [2](./packages/examples/src/worker/OBJLoaderWorker.ts)
- **WorkerTaskDirector: Potentially Infinite Execution**: [html](./packages/examples/potentially_infinite.html), [ts](./packages/examples/src/infinite/PotentiallyInfiniteExample.ts), **Worker**: [1](./packages/examples/src/worker/InfiniteWorkerExternalGeometry.ts), [2](./packages/examples/src/worker/InfiniteWorkerInternalGeometry.ts), [3](https://github.com/kaisalmen/WWOBJLoader/blob/main/packages/objloader2/src/worker/OBJLoader2Worker.ts), [4](./packages/examples/src/infinite/PotentiallyInfiniteExample.ts#L627-L668)
- Using [wtd-core](https://www.npmjs.com/package/wtd-core) only:
- **WorkerTask: Hello World**: [html](https://github.com/kaisalmen/wtd/blob/main/packages/examples/helloWorldWorkerTask.html), [ts](https://github.com/kaisalmen/wtd/blob/main/packages/examples/src/helloWorld/HelloWorldWorkerTask.ts), [worker](https://github.com/kaisalmen/wtd/blob/main/packages/examples/src/worker/HelloWorldWorker.ts)
- **WorkerTaskDirector: Hello World**: [html](https://github.com/kaisalmen/wtd/blob/main/packages/examples/helloWorldWorkerTaskDirector.html), [ts](https://github.com/kaisalmen/wtd/blob/main/packages/examples/src/helloWorld/helloWorldWorkerTaskDirector.ts), [worker](https://github.com/kaisalmen/wtd/blob/main/packages/examples/src/worker/HelloWorldWorker.ts)
- **WorkerTask: Inter-Worker Communication**: [html](https://github.com/kaisalmen/wtd/blob/main/packages/examples/workerCom.html), [ts](https://github.com/kaisalmen/wtd/blob/main/packages/examples/src/com/WorkerCom.ts), **Worker**: [1](https://github.com/kaisalmen/wtd/blob/main/packages/examples/src/worker/Com1Worker.ts) and [2](https://github.com/kaisalmen/wtd/blob/main/packages/examples/src/worker/Com2Worker.ts)
- Using [wtd-core](https://www.npmjs.com/package/wtd-core) and [wtd-three-ext](https://www.npmjs.com/package/wtd-three-ext):
- **WorkerTaskDirector: Transferables**: [html](https://github.com/kaisalmen/wtd/blob/main/packages/examples/transferables.html), [ts](https://github.com/kaisalmen/wtd/blob/main/packages/examples/src/transferables/TransferablesTestbed.ts), **Worker**: [1](https://github.com/kaisalmen/wtd/blob/main/packages/examples/src/worker/TransferableWorkerTest1.ts), [2](https://github.com/kaisalmen/wtd/blob/main/packages/examples/src/worker/TransferableWorkerTest2.ts), [3](https://github.com/kaisalmen/wtd/blob/main/packages/examples/src/worker/TransferableWorkerTest3.ts), [4](https://github.com/kaisalmen/wtd/blob/main/packages/examples/src/worker/TransferableWorkerTest4.ts)
- **WorkerTaskDirector: Three.js**: [html](https://github.com/kaisalmen/wtd/blob/main/packages/examples/threejs.html), [ts](https://github.com/kaisalmen/wtd/blob/main/packages/examples/src/threejs/Threejs.ts), **Worker**: [1](https://github.com/kaisalmen/wtd/blob/main/packages/examples/src/worker/HelloWorldThreeWorker.ts), [2](https://github.com/kaisalmen/wtd/blob/main/packages/examples/src/worker/OBJLoaderWorker.ts)
- **WorkerTaskDirector: Potentially Infinite Execution**: [html](https://github.com/kaisalmen/wtd/blob/main/packages/examples/potentially_infinite.html), [ts](https://github.com/kaisalmen/wtd/blob/main/packages/examples/src/infinite/PotentiallyInfiniteExample.ts), **Worker**: [1](https://github.com/kaisalmen/wtd/blob/main/packages/examples/src/worker/InfiniteWorkerExternalGeometry.ts), [2](https://github.com/kaisalmen/wtd/blob/main/packages/examples/src/worker/InfiniteWorkerInternalGeometry.ts), [3](https://github.com/kaisalmen/WWOBJLoader/blob/main/packages/objloader2/src/worker/OBJLoader2Worker.ts), [4](https://github.com/kaisalmen/wtd/blob/main/packages/examples/src/infinite/PotentiallyInfiniteExample.ts#L627-L668)

Try out all examples here: <https://kaisalmen.github.io/wtd>

### Usage

This shall give you an idea how you can use module worker with `WorkerTask` (derived from [WorkerTask: Hello World](./packages/examples/src/helloWorld/HelloWorldWorkerTask.ts)):
This shall give you an idea how you can use module worker with `WorkerTask` (derived from [WorkerTask: Hello World](https://github.com/kaisalmen/wtd/blob/main/packages/examples/src/helloWorld/HelloWorldWorkerTask.ts)):

```js
// let WorkerTask create the worker
Expand Down Expand Up @@ -88,22 +102,24 @@ If you run Vite locally you require a `nodejs` and `npm`. The Gitpod and local d
In any environment the dev server is reachable on port 8080.
## Execution Workflow
## WorkerTaskDirector Execution Workflow
The following table describes the currently implemented execution workflow of `WorkerTaskDirector`:
| WorkerTaskDirector (function) | Message cmd + direction | Worker (function) | Comment
| --- | :---: | --- | ---
| `registerTask` | | |
| `initTaskType` | **init ->** | `init` | User of `initTaskType` receives resolved promise after execution completion.<br>Sending `init` message is Optional
| `initTaskType` | **init ->** | `init` | User of `initTaskType` receives resolved promise after execution completion.<br>
Sending `init` message is Optional
| | **<- initComplete** | |
| `enqueueForExecution` | **exec ->** | `exec` |
| | **<- intermediate** | | Can be sent 0 to n times before **execComplete**
| | **<- execComplete** | | User of `enqueueForExecution` receives resolved promise after execution completion.<br>Callbacks `onIntermediate` and `onComplete` are used to handle message+payload.
| | **<- execComplete** | | User of `enqueueForExecution` receives resolved promise after execution completion.<br>
Callbacks `onIntermediate` and `onComplete` are used to handle message+payload.
## Main Branches
Main development takes place on branch [main](https://github.com/kaisalmen/three-wtm/tree/main).
Main development takes place on branch [main](https://github.com/kaisalmen/wtd/tree/main).
## Docs
Expand All @@ -113,7 +129,7 @@ Run `npm run doc` to create the markdown documentation in directory **docs** of
The orginal idea of a "TaskManager" was proposed by in Don McCurdy here [three.js issue 18234](https://github.com/mrdoob/three.js/issues/18234) It evolved from [three.js PR 19650](https://github.com/mrdoob/three.js/pull/19650) into this repository.
With version v2.0.0 the core library [wtd-core](./packages/wtd-core) and the three.js extensions [wtd-three-ext](./packages/wtd-three-ext) were separated into different npm packages [wtd-core](https://www.npmjs.com/package/wtd-core) and [wtd-three-ext](https://www.npmjs.com/package/wtd-three-ext).
With version v2.0.0 the core library [wtd-core](https://github.com/kaisalmen/wtd/blob/main/packages/wtd-core) and the three.js extensions [wtd-three-ext](https://github.com/kaisalmen/wtd/blob/main/packages/wtd-three-ext) were separated into different npm packages [wtd-core](https://www.npmjs.com/package/wtd-core) and [wtd-three-ext](https://www.npmjs.com/package/wtd-three-ext).
Happy coding!
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/kaisalmen/three-wtm.git"
"url": "git+https://github.com/kaisalmen/wtd.git"
},
"bugs": {
"url": "https://github.com/kaisalmen/three-wtm/issues"
"url": "https://github.com/kaisalmen/wtd/issues"
},
"scripts": {
"clean": "npm run clean --workspaces",
Expand All @@ -33,7 +33,7 @@
"reset:repo": "git clean -f -d -x"
},
"keywords": [],
"homepage": "https://github.com/kaisalmen/three-wtm#README",
"homepage": "https://github.com/kaisalmen/wtd#README",
"volta": {
"node": "20.10.0",
"npm": "10.2.3"
Expand Down
8 changes: 4 additions & 4 deletions packages/examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
},
"repository": {
"type": "git",
"url": "https://github.com/kaisalmen/three-wtm",
"directory": "packages/three-wtm"
"url": "https://github.com/kaisalmen/wtd",
"directory": "packages/wtd"
},
"homepage": "https://github.com/kaisalmen/three-wtm/blob/main/packages/examples/README.md",
"bugs": "https://github.com/kaisalmen/three-wtm/issues",
"homepage": "https://github.com/kaisalmen/wtd/blob/main/packages/examples/README.md",
"bugs": "https://github.com/kaisalmen/wtd/issues",
"author": {
"name": "kaisalmen",
"url": "https://www.kaisalmen.de"
Expand Down
2 changes: 1 addition & 1 deletion packages/wtd-core/LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021-2022 Kai Salmen
Copyright (c) 2021-2024 Kai Salmen

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
Loading

0 comments on commit f703acd

Please sign in to comment.