Skip to content

Commit 2cf5fd6

Browse files
committed
wip: expanded docs
1 parent 4fa43a5 commit 2cf5fd6

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/WorkerManager.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { type WorkerTaskInformation } from './types.js';
66
import * as errors from './errors.js';
77
import WorkerPool from './WorkerPool.js';
88

9-
// TODO: events
109
@CreateDestroy()
1110
class WorkerManager<Manifest extends WorkerManifest> {
1211
/**
@@ -17,7 +16,7 @@ class WorkerManager<Manifest extends WorkerManifest> {
1716
* @param options.manifest - The manifest defining the worker capabilities and operations.
1817
* @param [options.cores=1] - The number of cores to allocate for workers. Defaults to 1.
1918
* @param [options.logger=new Logger(this.name)] - An optional logger instance for logging activities. Defaults to a new logger.
20-
* @return {Promise<WorkerManager<Manifest>>} A promise that resolves to a new WorkerManager instance.
19+
* @return A promise that resolves to a new WorkerManager instance.
2120
*/
2221
public static async createWorkerManager<Manifest extends WorkerManifest>({
2322
workerFactory,

src/worker.ts

+16
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,21 @@ import { expose } from './expose.js';
55
* This is an example worker script used purely for example and internal testing
66
*/
77
const worker = {
8+
/**
9+
* A test function that returns the string 'hello world!'.
10+
*/
811
test: async (): Promise<{ data: 'hello world!' }> => {
912
return { data: 'hello world!' };
1013
},
14+
/**
15+
* Adds two parameters `a` and `b` together.
16+
*/
1117
add: async (data: { a: number; b: number }) => {
1218
return { data: data.a + data.b };
1319
},
20+
/**
21+
* Subtracts two parameters `a` and `b` together.
22+
*/
1423
sub: async (data: { a: number; b: number }) => {
1524
return { data: data.a - data.b };
1625
},
@@ -21,6 +30,10 @@ const worker = {
2130
}
2231
return { data: acc };
2332
},
33+
/**
34+
* Sleeps for the provided amount of time in milliseconds.
35+
* @param data
36+
*/
2437
sleep: async (data: number) => {
2538
await new Promise<void>((resolve) => {
2639
const timer = setTimeout(resolve, data);
@@ -29,6 +42,9 @@ const worker = {
2942
});
3043
return { data: undefined };
3144
},
45+
/**
46+
* Test function that takes a transferred ArrayBuffer and fills it with 0x0F bytes.
47+
*/
3248
transferBuffer: async (data: ArrayBuffer, _transferList?: [ArrayBuffer]) => {
3349
const buffer = Buffer.from(data, 0, data.byteLength);
3450
buffer.fill(0xf);

0 commit comments

Comments
 (0)