AsyncIterator
一个使用requestAnimationFrame批量处理大型数据集而不锁定UI的异步迭代器。
// The dataset
var myArr = [];
// Number of operations per call
var batchSize = 1000;
// The actual processing method
function work(item, index) {
// Do something for each item
}
// Start iterator, it will return a promise
var promise = asyncIterator(myArr, work, batchSize);
// When promise is resolved, output results
promise.done