Package Exports
- chunkify
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (chunkify) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
chunkify
An ES6-developed functional API that prevents long-running scripts from blocking the JavaScript thread.
Install
$ npm install --save chunkifyUsage
Import the module:
import chunkify from 'chunkify'Options
In API methods, an optional options object may provide any subset of the following data:
chunk: the number of items inarrayto successively invokefnon before yielding control of the main thread.- default value is
1 - must be positive
- aliases:
chunksize
- default value is
delay: the minimal time in milliseconds to wait before continuing to invokefnonarray.- default value is
0 - must be non-negative
- aliases:
yield,yieldtime,delaytime
- default value is
scope: the object on which the processing functionfnis invoked on.- default value is
null - must not be a
Number,Boolean, orundefined
- default value is
API
chunkify.each(Array array, Function fn, [Object options])
fn is successively invoked on array. At every chunkth invocation, control is yielded back to the thread. After (at least) delay milliseconds, fn picks up where it left off. This continues until all items in array have been processed by fn.
Returns a Promise that resolves with array when fn has been invoked on all items in array.
If any invocation of fn throws an error, the promise is rejected with an object {error, item}, where error is the caught Error, and item is the member of array where fn.call(options.scope, item) threw. No further processing happens after the failure.
chunkify.map(Array array, Function fn, [Object options])
Identical to chunkify.each, except the returned Promise resolves with the array mapped by fn.
Future Plans
Expose a generator-friendly API.
Contributing
Development is in snake_case ES6.
Get the source.
$ git clone git@github.com:yangmillstheory/chunkifyInstall dependencies.
$ npm installCompile sources.
$ node_modules/.bin/gulpRun tests.
$ npm testLicense
MIT © 2015, Victor Alvarez