0.0.1 • Published 10 years ago

foreach-batch v0.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
10 years ago

forEachBatch

Build Status

A simple combinator for deferred batch processing to keep the UI responsive under long-running computations.

Syntax

forEach(arr, callback, batchSize[, progressCallback[, timeoutDelay])

Description

I wrote this to build a big Lunr.js search index without blocking the UI and without using WebWorkers.

var forEachBatch = require('foreach-batch');

// Process everything at once - will possibly block the UI
stuff.forEach(someExpensiveFunction);

// Process in batches of 10 - giving the UI some breathing room in between batches
forEachBatch(stuff, someExpensiveFunction, 10, function(progress) {
  console.log(progress); // ...and we can keep track of our progress
}, 1000); // ...and we can control how long to wait between batches
0.0.1

10 years ago