Skip to content

Commit

Permalink
Merge pull request #2 from koyopro/feature/terminate_all_workers
Browse files Browse the repository at this point in the history
rename: terminateAllThreads -> terminateAllWorkers
  • Loading branch information
koyopro authored Dec 29, 2024
2 parents c5c2303 + d8f0ab3 commit 9fb434d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ worker.once('error', (error) => {
});
```

### Terminating All Threads
By calling `terminateAllThreads()`, you can terminate all worker threads that have been started with `launch()`. The return value is an array of exit codes.
### Terminating All Worker Threads
By calling `terminateAllWorkers()`, you can terminate all worker threads that have been started with `launch()`. The return value is an array of exit codes.

```typescript
import { terminateAllThreads } from "sync-actions";
import { terminateAllWorkers } from "sync-actions";

const exitCodes = await terminateAllThreads();
const exitCodes = await terminateAllWorkers();
```

## Environment Variables
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const defineSyncWorker = <F extends Actions>(filepath: string, actions: F
*
* @returns A Promise that resolves to an array of exit codes for each worker.
*/
export const terminateAllThreads = async (): Promise<(number | undefined)[]> =>
export const terminateAllWorkers = async (): Promise<(number | undefined)[]> =>
Promise.all(workers.map((worker) => worker.terminate()));

const makeTmpFilePath = (filename: string) => {
Expand Down
6 changes: 3 additions & 3 deletions tests/multi.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { terminateAllThreads } from "../src";
import { terminateAllWorkers } from "../src";
import actions from "./worker";


Expand All @@ -12,13 +12,13 @@ test("launch multiple workers", async () => {
client2.worker.terminate();
});

test("terminateAllThreads()", async () => {
test("terminateAllWorkers()", async () => {
const client1 = actions.launch();
const client2 = actions.launch();
const client3 = actions.launch();
expect(await client3.worker.terminate()).toBe(0)

await terminateAllThreads();
await terminateAllWorkers();

// all threads are already terminated
expect(await client1.worker.terminate()).toBeUndefined();
Expand Down

0 comments on commit 9fb434d

Please sign in to comment.