Skip to content

Function: idleIterator() ​

ts
function idleIterator<T>(array, callbackfn): void;

Iterates over an array during browser idle time to avoid blocking the main thread. 在浏览器空闲时间迭代数组,避免阻塞主线程。

Type Parameters ​

Type Parameter
T

Parameters ​

ParameterTypeDescription
arrayT[]The array to iterate over / 要迭代的数组
callbackfn(item, index) => voidFunction to execute on each item / 对每个项目执行的函数

Returns ​

void

Example ​

ts
// Runs callbacks during browser idle time — output is deferred, not immediate
const items = [1, 2, 3]
idleIterator(items, (item, index) => {
  console.log(index, item)
})

Since ​

1.0.0

Released under the MIT License.