array-chunk-reader
Advanced tools
Comparing version 0.1.7 to 0.1.8
@@ -68,6 +68,7 @@ (function () { | ||
if (info.from >= length) { | ||
if (info.from >= length || this.__stopped) { | ||
let result = {}; | ||
result.avgChunkTime = lastInfo.avgTime || 0; | ||
result.chunkCount = lastInfo.iteration || 0; | ||
this.__stopped && this.options.log && console.log("Array chunk reader has been stopped"); | ||
return callback(null, info, result); | ||
@@ -140,6 +141,10 @@ } | ||
rej(new Error("Array chunk reader failed")); | ||
rej(new Error("Array chunk reader is failed")); | ||
}); | ||
}); | ||
} | ||
stop() { | ||
this.__stopped = true; | ||
} | ||
} | ||
@@ -146,0 +151,0 @@ |
{ | ||
"name": "array-chunk-reader", | ||
"version": "0.1.7", | ||
"version": "0.1.8", | ||
"description": "Module for reading array by chunks using promise", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
@@ -38,1 +38,4 @@ # Install | ||
returns the current chunk size | ||
### .stop() | ||
cancel all next chunks after the current |
@@ -17,3 +17,3 @@ "use strict"; | ||
describe('api', function() { | ||
describe('#constructor', function () { | ||
describe('.constructor', function () { | ||
it('check instance', function () { | ||
@@ -25,3 +25,3 @@ reader = new ArrayChunkReader(array, {log: false, size: size}); | ||
describe('#start()', function () { | ||
describe('.start()', function () { | ||
it('check returned fn value', function () { | ||
@@ -55,3 +55,22 @@ let counter = 1; | ||
describe('#getCurrentChunkSize()', function () { | ||
describe('.stop()', function () { | ||
it('check returned fn value', function () { | ||
let counter = 0; | ||
let size = 5; | ||
reader = new ArrayChunkReader(array, {size: size, log: false}); | ||
return reader.start(() => { | ||
counter++; | ||
if(counter == 3) { | ||
reader.stop(); | ||
} | ||
}).then((res) => { | ||
assert.equal(counter, size); | ||
}); | ||
}); | ||
}); | ||
describe('.getCurrentChunkSize()', function () { | ||
it('check chunk size in every fnChunk', function () { | ||
@@ -67,3 +86,3 @@ let fn = (value) => { | ||
}); | ||
}); | ||
}); | ||
}); | ||
@@ -70,0 +89,0 @@ |
8420
211
41