Comparing version 0.11.2 to 0.11.3
@@ -34,3 +34,3 @@ // Core routines for event emitters | ||
var FEED_PARAMETERS = ['since', 'limit', 'feed', 'heartbeat', 'filter', 'include_docs', 'view', 'style']; | ||
var FEED_PARAMETERS = ['since', 'limit', 'feed', 'heartbeat', 'filter', 'include_docs', 'view', 'style', 'conflicts']; | ||
@@ -557,7 +557,2 @@ var EventEmitter = events.EventEmitter2 || events.EventEmitter; | ||
if(!self.is_db_updates && !self.caught_up && change.seq == self.original_db_seq) { | ||
self.caught_up = true | ||
self.emit('catchup', change.seq) | ||
} | ||
if(typeof self.filter !== 'function') | ||
@@ -584,4 +579,8 @@ return self.on_good_change(change); | ||
return self.on_good_change(change); | ||
} else | ||
} else { | ||
self.log.debug('Builtin filter FAIL for change: ' + change.seq); | ||
// Even with a filtered change, a "catchup" event might still be appropriate. | ||
self.check_for_catchup(change.seq) | ||
} | ||
} | ||
@@ -606,4 +605,20 @@ | ||
self.emit('change', change); | ||
self.check_for_catchup(change.seq) | ||
} | ||
Feed.prototype.check_for_catchup = function check_for_catchup(seq) { | ||
var self = this | ||
if (self.is_db_updates) | ||
return | ||
if(self.caught_up) | ||
return | ||
if(seq < self.original_db_seq) | ||
return | ||
self.caught_up = true | ||
self.emit('catchup', seq) | ||
} | ||
Feed.prototype.on_inactivity = function on_inactivity() { | ||
@@ -610,0 +625,0 @@ var self = this; |
@@ -247,2 +247,5 @@ // Changes stream | ||
if(self.source && typeof self.source.abort == 'function') | ||
return self.source.abort() | ||
if(self.source && typeof self.source.destroy === 'function') | ||
@@ -249,0 +252,0 @@ self.source.destroy() |
{ "name": "follow" | ||
, "version": "0.11.2" | ||
, "version": "0.11.3" | ||
, "author": { "name": "Jason Smith" | ||
, "email": "jhs@iriscouch.com" } | ||
, "contributors": [ "Jarrett Cruger <jcrugzz@gmail.com>" ] | ||
, "description": "Extremely robust, fault-tolerant CouchDB changes follower" | ||
@@ -6,0 +7,0 @@ , "license": "Apache 2.0" |
@@ -155,3 +155,3 @@ # Follow: CouchDB changes and db updates notifier for NodeJS | ||
* **change** | `function(change)` | A change occured; passed the change object from CouchDB | ||
* **catchup** | `function(seq_id)` | The feed has caught up to the *update_seq* from the confirm step. Assuming no subsequent changes, you have seen all the data. *Always fires before the final **change** event.* | ||
* **catchup** | `function(seq_id)` | The feed has caught up to the *update_seq* from the confirm step. Assuming no subsequent changes, you have seen all the data. | ||
* **wait** | Follow is idle, waiting for the next data chunk from CouchDB | ||
@@ -158,0 +158,0 @@ * **timeout** | `function(info)` | Follow did not receive a heartbeat from couch in time. The passed object has `.elapsed_ms` set to the elapsed time |
@@ -95,2 +95,17 @@ var tap = require('tap') | ||
test('Catchup events', function(t) { | ||
t.ok(couch.rtt(), 'The couch RTT is known') | ||
var feed = follow(couch.DB, function() {}) | ||
var last_seen = 0 | ||
feed.on('change', function(change) { last_seen = change.seq }) | ||
feed.on('catchup', function(id) { | ||
t.equal(last_seen, 3, 'The catchup event fires after the change event that triggered it') | ||
t.equal(id , 3, 'The catchup event fires on the seq_id of the latest change') | ||
feed.stop() | ||
t.end() | ||
}) | ||
}) | ||
test('Data due on a paused feed', function(t) { | ||
@@ -125,3 +140,2 @@ t.ok(couch.rtt(), 'The couch RTT is known') | ||
feed.on('change', function(change) { | ||
console.error('CHANGE: %j', change) | ||
if(change.seq == 1) { | ||
@@ -191,8 +205,10 @@ feed.pause() | ||
test('Events for DB confirmation and hitting the original seq', function(t) { | ||
t.plan(7) | ||
var feed = follow(couch.DB, on_change) | ||
var events = { 'confirm':null, 'catchup':null } | ||
var events = { 'confirm':null } | ||
feed.on('confirm', function(db) { events.confirm = db }) | ||
feed.on('catchup', function(seq) { events.catchup = seq }) | ||
feed.on('catchup', caught_up) | ||
// This will run 3 times. | ||
function on_change(er, ch) { | ||
@@ -204,9 +220,10 @@ t.false(er, 'No problem with the feed') | ||
t.equal(events.confirm && events.confirm.update_seq, 3, 'Confirm event got the update_seq right') | ||
} | ||
} | ||
t.ok(events.catchup, 'Catchup event fired') | ||
t.equal(events.catchup, 3, 'Catchup event fired on update 3') | ||
function caught_up(seq) { | ||
t.equal(seq, 3, 'Catchup event fired on update 3') | ||
feed.stop() | ||
t.end() | ||
} | ||
feed.stop() | ||
t.end() | ||
} | ||
@@ -213,0 +230,0 @@ }) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
225608
27
2949