From aaab6d02b5c1298ada27c0dbbf5e66aa253ee89a Mon Sep 17 00:00:00 2001 From: smikhalevski Date: Mon, 11 Dec 2023 19:56:55 +0300 Subject: [PATCH] Better naming --- README.md | 3 +-- src/main/WorkPool.ts | 6 +++--- src/main/{raceSignals.ts => composeSignals.ts} | 2 +- src/main/index.ts | 2 +- src/test/{raceSignals.test.ts => composeSignals.test.ts} | 8 ++++---- 5 files changed, 10 insertions(+), 11 deletions(-) rename src/main/{raceSignals.ts => composeSignals.ts} (88%) rename src/test/{raceSignals.test.ts => composeSignals.test.ts} (68%) diff --git a/README.md b/README.md index 14c6b63..c97a2db 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,6 @@ npm install --save-prod parallel-universe - [`Lock`](#lock) - [`Blocker`](#blocker) - [`PubSub`](#pubsub) -- [`untilTruthy`](#untiltruthy) - [`repeatUntil`](#repeatuntil) - [`sleep`](#sleep) - [`raceTimeout`](#racetimeout) @@ -321,7 +320,7 @@ pubSub.publish('Pluto'); # `repeatUntil` -Invokes a callback until the condition is met. +Invokes a callback multiple times until the condition is met. ```ts repeatUntil( diff --git a/src/main/WorkPool.ts b/src/main/WorkPool.ts index e11e097..4e360f5 100644 --- a/src/main/WorkPool.ts +++ b/src/main/WorkPool.ts @@ -16,7 +16,7 @@ export class WorkPool { /** * The queue that holds submitted jobs. */ - private _queue = new AsyncQueue(); + private _jobQueue = new AsyncQueue(); /** * Active workers and workers with pending termination. @@ -48,7 +48,7 @@ export class WorkPool { */ submit(cb: AbortableCallback): Promise { return new Promise((resolve, reject) => { - this._queue.add({ callback: cb, resolve, reject }); + this._jobQueue.add({ callback: cb, resolve, reject }); }); } @@ -89,7 +89,7 @@ export class WorkPool { // Spawn additional workers for (let i = 0; i < size; ++i) { - _workers.push(new Worker(this._queue)); + _workers.push(new Worker(this._jobQueue)); } return Promise.all(promises).then(noop); diff --git a/src/main/raceSignals.ts b/src/main/composeSignals.ts similarity index 88% rename from src/main/raceSignals.ts rename to src/main/composeSignals.ts index f614f8c..f832e6e 100644 --- a/src/main/raceSignals.ts +++ b/src/main/composeSignals.ts @@ -3,7 +3,7 @@ * * @param signals The signals to observe. */ -export function raceSignals(signals: AbortSignal[]): AbortSignal { +export function composeSignals(signals: AbortSignal[]): AbortSignal { const abortController = new AbortController(); const abortListener = () => { diff --git a/src/main/index.ts b/src/main/index.ts index 6b41fe6..8d9f205 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -4,7 +4,7 @@ export { Executor } from './Executor'; export { Lock } from './Lock'; export { PubSub } from './PubSub'; export { WorkPool } from './WorkPool'; -export { raceSignals } from './raceSignals'; +export { composeSignals } from './composeSignals'; export { raceTimeout } from './raceTimeout'; export { repeatUntil } from './repeatUntil'; export { sleep } from './sleep'; diff --git a/src/test/raceSignals.test.ts b/src/test/composeSignals.test.ts similarity index 68% rename from src/test/raceSignals.test.ts rename to src/test/composeSignals.test.ts index 029d2f2..e63621b 100644 --- a/src/test/raceSignals.test.ts +++ b/src/test/composeSignals.test.ts @@ -1,11 +1,11 @@ -import { raceSignals } from '../main'; +import { composeSignals } from '../main'; -describe('raceSignals', () => { +describe('composeSignals', () => { test('aborts if any of signals is aborted', () => { const abortController1 = new AbortController(); const abortController2 = new AbortController(); - const signal = raceSignals([abortController1.signal, abortController2.signal]); + const signal = composeSignals([abortController1.signal, abortController2.signal]); expect(signal.aborted).toBe(false); @@ -20,7 +20,7 @@ describe('raceSignals', () => { abortController2.abort(); - const signal = raceSignals([abortController1.signal, abortController2.signal]); + const signal = composeSignals([abortController1.signal, abortController2.signal]); expect(signal.aborted).toBe(true); });