X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Futils.ts;h=c568a29a049eda2de26cf9bd99d63e613294bc3f;hb=ecde6ea8c439bbdd9dc2ca118731b5006a1a9884;hp=d15f63c557e813aec9fdeeae7f993be8f8adedc4;hpb=260d2e6df285501c69e0d4f6d29fcd4b5266ed54;p=poolifier.git diff --git a/src/utils.ts b/src/utils.ts index d15f63c5..c568a29a 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,5 +1,6 @@ -import * as os from 'node:os' import { getRandomValues } from 'node:crypto' +import * as os from 'node:os' + import type { KillBehavior } from './worker/worker-options.js' /** @@ -135,7 +136,7 @@ export const isPlainObject = (value: unknown): value is object => * * @typeParam KB - Which specific KillBehavior type to test against. * @param killBehavior - Which kind of kill behavior to detect. - * @param value - Any value. + * @param value - Unknown value. * @returns `true` if `value` was strictly equals to `killBehavior`, otherwise `false`. * @internal */ @@ -197,18 +198,22 @@ export const max = (...args: number[]): number => * @param fn - The function to wrap. * @param context - The context to bind the function to. * @returns The wrapped function. + * + * @typeParam A - The function's arguments. + * @typeParam R - The function's return value. + * @typeParam C - The function's context. * @internal */ // eslint-disable-next-line @typescript-eslint/no-explicit-any -export const once = ( +export const once = ( fn: (...args: A) => R, - context: T + context: C ): ((...args: A) => R) => { let result: R return (...args: A) => { // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition if (fn != null) { - result = fn.apply(context, args) + result = fn.apply(context, args) ;(fn as unknown as undefined) = (context as unknown as undefined) = undefined }