Skip to content

Commit

Permalink
Changes to README & removed debugging statements
Browse files Browse the repository at this point in the history
  • Loading branch information
W4G1 committed Dec 18, 2023
1 parent 6de99b7 commit 45b290c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ Depending on the environment, it uses [Worker Threads](https://nodejs.org/api/wo
npm install multithreading
```

#### Node.js
To use the `multithreading` package with Node.js, it is necessary to install the [web-worker](https://www.npmjs.com/package/web-worker) package because Node.js does not support web workers by default.

```bash
npm install web-worker
```

## Usage

#### Minimal example
Expand Down Expand Up @@ -95,3 +102,8 @@ await Promise.all([

console.log(user.balance); // 15
```
In this example, the `addBalance` function integrates the external `add` function into a multithreaded environment. The `yield` statement is used to declare external dependencies, ensuring that the required functions and data are available to the threaded function.

As with previous examples, the shared state is managed using `$claim` and `$unclaim` to guarantee proper synchronization and prevent data conflicts.

> External functions like `add` cannot have external dependencies themselves. All variables and functions used by an external function must be declared within the function itself.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "multithreading",
"version": "0.1.8",
"description": "⚡ Multithreading functions in JavaScript with a focus on performance and bundle size",
"version": "0.1.9",
"description": "⚡ Multithreading functions in JavaScript, designed to be as simple and fast as possible.",
"author": "Walter van der Giessen <[email protected]>",
"homepage": "https://github.com/W4G1/multithreading/tree/main#readme",
"license": "MIT",
Expand Down
6 changes: 3 additions & 3 deletions src/lib/worker.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ globalThis.onmessage = async (e: MessageEvent<MainEvent>) => {
Thread.handleInvocation(e.data[$.EventValue]);
break;
case $.ClaimAcceptance:
console.log("Claimed", e.data[$.EventValue][$.Name]);
// console.log("Claimed", e.data[$.EventValue][$.Name]);
Thread.handleClaimAcceptance(e.data[$.EventValue]);
break;
}
Expand Down Expand Up @@ -65,7 +65,7 @@ globalThis.$unclaim = function $unclaim(value: Object) {

if (--Thread.valueInUseCount[valueName] > 0) return;

console.log("Unclaimed", valueName);
// console.log("Unclaimed", valueName);

Thread.valueClaimMap.delete(valueName);
globalThis.postMessage({
Expand Down Expand Up @@ -120,7 +120,7 @@ namespace Thread {
gen.next();
const returnValue = await gen.next();

console.log("Returned", returnValue.value);
// console.log("Returned", returnValue.value);

globalThis.postMessage({
[$.EventType]: $.Return,
Expand Down

0 comments on commit 45b290c

Please sign in to comment.