diff --git a/README.md b/README.md index fe8d08c0..df6ec0bc 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ Please consult our [general guidelines](#general-guidelines). - Performance [benchmarks](https://github.com/poolifier/poolifier-web-worker/blob/master/benchmarks/README.md) ✔ -- Zero cost abstraction for multiple JS runtime support ✔ +- Multiple JS runtime support at zero cost abstraction ✔ - No runtime dependencies ✔ - Support for ESM and TypeScript ✔ - Support for diff --git a/src/pools/selection-strategies/selection-strategies-utils.ts b/src/pools/selection-strategies/selection-strategies-utils.ts index 5c16e6ed..b8fdb7b1 100644 --- a/src/pools/selection-strategies/selection-strategies-utils.ts +++ b/src/pools/selection-strategies/selection-strategies-utils.ts @@ -1,8 +1,4 @@ -import { - availableParallelism, - runtime, - unsupportedJsRuntime, -} from '../../utils.ts' +import { availableParallelism, runtime } from '../../utils.ts' import type { IPool } from '../pool.ts' import type { IWorker } from '../worker.ts' import { FairShareWorkerChoiceStrategy } from './fair-share-worker-choice-strategy.ts' @@ -67,7 +63,6 @@ const cpusCycleTimeWeight = (cpus: { speed: number }[]): number => { const computedDefaultWorkerWeight: number = await (async (): Promise => { return await { - unknown: unsupportedJsRuntime, browser: () => { const estCpuSpeed = estimatedCpuSpeed() return cpusCycleTimeWeight( diff --git a/src/utils.ts b/src/utils.ts index 7acdf020..d2b27f1f 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -258,15 +258,6 @@ const isDeno: boolean = !!(globalThis as any).Deno // deno-lint-ignore no-explicit-any const isBrowser: boolean = !!(globalThis as any).navigator -/** - * Throws an error indicating that the current JavaScript runtime environment is unsupported. - * - * @internal - */ -export const unsupportedJsRuntime = () => { - throw new Error('Unsupported JavaScript runtime environment') -} - /** * JavaScript runtime environments enumeration. * @@ -279,22 +270,21 @@ export enum JavaScriptRuntimes { } /** - * JavaScript runtime environments. + * JavaScript runtime environment. * * @internal */ -export const runtime: JavaScriptRuntimes | 'unknown' = (() => { +export const runtime: JavaScriptRuntimes = (() => { if (isBun) return JavaScriptRuntimes.bun if (isDeno) return JavaScriptRuntimes.deno if (isBrowser) return JavaScriptRuntimes.browser - return 'unknown' + throw new Error('Unsupported JavaScript runtime environment') })() const isMainThread: boolean | undefined = await (async (): Promise< boolean | undefined > => { return await { - unknown: unsupportedJsRuntime, browser: () => undefined, deno: () => undefined, bun: async () => { @@ -312,7 +302,6 @@ const isMainThread: boolean | undefined = await (async (): Promise< */ export const environment: string = await (async (): Promise => { return await { - unknown: unsupportedJsRuntime, browser: () => 'production', deno: () => { // deno-lint-ignore ban-ts-comment