Skip to content

Commit

Permalink
Fix issue with flush not repeating
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeyBurkman committed Jul 22, 2016
1 parent d0aa774 commit 567a3a2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ module.exports = function(opts) {
/////

function setFlushInterval() {
clearTimeout(_timeout);
clearInterval(_timeout);
if (_flushInterval < Infinity) {
_timeout = setTimeout(flush, _flushInterval);
_timeout = setInterval(flush, _flushInterval);
}
}

Expand Down
29 changes: 29 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,35 @@ describe(__filename, function() {
}, 250);

});

it('Should flush continuously', function(done) {
var flush = sinon.stub();

var x51 = mod({
flush: flush,
flushInterval: 50
});

x51.push({});

setTimeout(function() {
expect(flush.callCount).to.eql(1);
var items = flush.getCall(0).args[0];
expect(items.length).to.eql(1);

x51.push({});
x51.push({});

// Should flush a second time
setTimeout(function() {
expect(flush.callCount).to.eql(2);
var items = flush.getCall(1).args[0];
expect(items.length).to.eql(2);

done();
}, 60);
}, 70);
});

it('Should not lose records if flush throws an error', function() {
var flush = sinon.stub();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "x51",
"version": "2.0.0",
"version": "2.0.1",
"description": "Utility for aggregating and flushing items to be processed",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 567a3a2

Please sign in to comment.