Skip to content

Commit

Permalink
updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaWise committed Jun 20, 2023
1 parent bea19ef commit 487fe37
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
A worker thread pool for CPU-bound tasks. It requires no configuration and has many powerful features:

- [Generator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*) and [AsyncGenerator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function*) function support
* Worker functions can be [generator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*) functions or [async generator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function*) functions, making it easy to stream results back to the main thread. Iteration happens eagerly, to maximize parallelism (i.e., the main thread cannot pause the generator function).
* Worker functions can be [generator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*) functions or [async generator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function*) functions, making it easy to stream results back to the main thread. Iteration happens eagerly, to maximize parallelism (i.e., the main thread does not pause the generator function).
- Functions (callbacks) as arguments
* Functions can be passed to worker tasks. They become `async` functions in the worker thread, using [MessagePort](https://nodejs.org/docs/latest/api/worker_threads.html#class-messageport) for communication under the hood.
- Cancellation support
Expand Down Expand Up @@ -37,7 +37,7 @@ const result = await pool.call('add', 2, 2); // => 4
exports.add = (a, b) => a + b;
```

### Zero-copy example
### Example: Zero-copy

```js
const ThreadPool = require('wise-workers');
Expand Down Expand Up @@ -67,7 +67,7 @@ exports.compress = (data) => {
};
```

### Generator example
### Example: Generator function

When calling a generator function, you will get an [async iterable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of) object.

Expand Down Expand Up @@ -110,7 +110,7 @@ exports.readFile = function* (filename, chunkSize = 1024 * 16) {
};
```

### Callback function example
### Example: Callback function

You an pass callback functions to the worker, but they must be in the top-level arguments (they can't be nested within some other object). Callback functions can also be `async` functions.

Expand Down Expand Up @@ -141,7 +141,7 @@ exports.search = async (searchTerm, filter) => {

> Currently, callback functions do not support "zero-copy" data transfer in their arguments or return values. This restriction may be lifted in the future.
### AbortSignal example
### Example: AbortSignal (cancellation)

Calling `controller.abort()` will forcefully terminate the thread that's assigned to the associated task.

Expand Down

0 comments on commit 487fe37

Please sign in to comment.