chunk iteration now is sync for arrays smaller than a chunk...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2020-11-02 04:29:12 +03:00
parent 14ea5dca05
commit 965acefe61
2 changed files with 11 additions and 1 deletions

View File

@ -230,12 +230,22 @@ var makeChunkIter = function(iter, wrapper){
var res = []
var _wrapper = wrapper.bind(this, res, func, this)
// special case...
// no need to setTimeout(..) if smaller than size...
if(this.length <= size){
var res = this[iter](_wrapper, ...rest)
return Promise.all(
postChunk ?
postChunk.call(this, this, res, 0)
: res) }
return new Promise(function(resolve, reject){
var next = function(chunks){
setTimeout(function(){
var chunk, val
res.push(
val = (chunk = chunks.shift())[iter](_wrapper, ...rest))
// handle chunk...
postChunk
&& postChunk.call(that,
chunk.map(function([i, v]){ return v }),

View File

@ -1,6 +1,6 @@
{
"name": "ig-types",
"version": "2.0.19",
"version": "2.0.20",
"description": "Generic JavaScript types and type extensions...",
"main": "main.js",
"scripts": {