this._writer = new PassThroughStream(options); this._onError = this.emit.bind(this, "error");
ended = true; this._reader.end(); setImmediate(this.emit.bind(this, "close"));
_transform(chunk, enc, done) { //save the number of running process this.running++; // preforms data transformation(data, encoding, "push" func to write the data, "end" function to call) const pushFunction = this.push.bind(this); const endFunction = this._onComplete.bind(this); this.userTransform(chunk, enc, pushFunction, endFunction); console.log('Runnning chunk ', chunk); done(); }
it('stops when pushing fails', function(done){ consumer = new Consumer(storage, 'foobar', 'consumer1'); consumer.on('caught-up', () => { storage.write({type: 'Foobar', id: 1}); storage.write({type: 'Foobar', id: 2}); storage.write({type: 'Foobar', id: 3}); }); const push = consumer.push.bind(consumer); consumer.push = (doc) => push(doc) && false; consumer.on('data', document => { expect(document.id).to.be(1); setTimeout(done, 10); }); });
it('stops when push fails during catching up', function(done){ consumer = new Consumer(storage, 'foobar', 'consumer1'); const push = consumer.push.bind(consumer); consumer.push = (doc) => push(doc) && false; storage.write({ type: 'Foobar', id: 1 }); storage.write({ type: 'Foobar', id: 2 }); storage.write({ type: 'Foobar', id: 3 }, () => { expect(consumer.position).to.be(0); consumer.on('data', document => { expect(document.id).to.be(1); setTimeout(done, 10); }); }); });
_transform(chunk, enc, done) { //save the number of running process this.running++; // preforms data transformation(data, encoding, "push" func to write the data, "end" function to call) const pushFunction = this.push.bind(this); const endFunction = this._onComplete.bind(this); this.userTransform(chunk, enc, pushFunction, endFunction); console.log('Runnning chunk ', chunk); if(this.running < this.concurrency) { done(); } else { this.continueCallback = done; } }