Skip to content

Function: after()

ts
function after<TArgs, TResult>(n, fn): (...args) => TResult | undefined;

Creates a function that invokes fn only after being called n times. 创建仅在第 n 次及之后才会执行 fn 的包装函数。

Type Parameters

Type ParameterDescription
TArgs extends unknown[]Argument tuple / 参数元组
TResultReturn type / 返回类型

Parameters

ParameterTypeDescription
nnumberInvocation threshold / 触发阈值
fn(...args) => TResultTarget function / 目标函数

Returns

Wrapped function / 包装函数

(...args) => TResult | undefined

Example

ts
const run = after(3, () => 'ok')
run()
run()
run() // => 'ok'

Since

1.2.0

Released under the MIT License.