Comparing version 0.6.0 to 0.6.1
15
feed.js
@@ -49,2 +49,3 @@ // Core routines for event emitters | ||
self.since = 0; | ||
self.caught_up = false | ||
self.retry_delay = INITIAL_RETRY_DELAY; // ms | ||
@@ -136,3 +137,5 @@ | ||
self.original_db_seq = db.update_seq | ||
self.log.debug('Confirmed db: ' + self.db_safe); | ||
self.emit('confirm', db); | ||
@@ -149,3 +152,8 @@ if(self.since == 'now') { | ||
self.emit('confirm'); | ||
// If the next change would come after the current update_seq, just fake a catchup event now. | ||
if(self.original_db_seq == self.since) { | ||
self.caught_up = true | ||
self.emit('catchup', db.update_seq) | ||
} | ||
return self.query(); | ||
@@ -501,2 +509,7 @@ } | ||
if(!self.caught_up && change.seq >= self.original_db_seq) { | ||
self.caught_up = true | ||
self.emit('catchup', change.seq) | ||
} | ||
if(typeof self.filter !== 'function') | ||
@@ -503,0 +516,0 @@ return self.on_good_change(change); |
{ "name": "follow" | ||
, "version": "0.6.0" | ||
, "version": "0.6.1" | ||
, "author": { "name": "Jason Smith" | ||
@@ -4,0 +4,0 @@ , "email": "jhs@iriscouch.com" } |
@@ -56,2 +56,3 @@ # Follow: CouchDB changes notifier for NodeJS | ||
<a name="options"></a> | ||
All of the CouchDB _changes options are allowed. See http://guide.couchdb.org/draft/notifications.html. | ||
@@ -110,2 +111,27 @@ | ||
<a name="events"></a> | ||
## Events | ||
The feed object is an EventEmitter. There are a few ways to get a feed object: | ||
* Use the object API above | ||
* Use the return value of `follow()` | ||
* In the callback to `follow()`, the *this* variable is bound to the feed object. | ||
Once you've got one, you can subscribe to these events: | ||
* **start** | Before any i/o occurs | ||
* **confirm_request** | `function(req)` | The database confirmation request is sent; passed the `request` object | ||
* **confirm** | `function(db_obj)` | The database is confirmed; passed the couch database object | ||
* **change** | `function(change)` | A change occured; passed the change object from CouchDB | ||
* **catchup** | `function(seq_id)` | The feed has reached the latest change the database had when it was confirmed (i.e. its `update_seq`). Assuming no changes since the confirmation step, this means you have seen the entire database. | ||
* **wait** | Follow is idle, waiting for the next data chunk from CouchDB | ||
* **timeout** | `function(info)` | Follow did not receive a heartbeat from couch in time. The passed object has `.elapsed_ms` set to the elapsed time | ||
* **retry** | `function(info)` | A retry is scheduled (usually after a timeout or disconnection). The passed object has | ||
* `.since` the current sequence id | ||
* `.after` the milliseconds to wait before the request occurs (on an exponential fallback schedule) | ||
* `.db` the database url (scrubbed of basic auth credentials) | ||
* **stop** | The feed is stopping, because of an error, or because you called `feed.stop()` | ||
* **error** | `function(err)` | An error occurs | ||
## Error conditions | ||
@@ -128,5 +154,5 @@ | ||
ok test/couch.js ...................................... 10/10 | ||
ok test/follow.js ..................................... 30/30 | ||
ok test/issues.js ..................................... 29/29 | ||
total ................................................. 72/72 | ||
ok test/follow.js ..................................... 38/38 | ||
ok test/issues.js ..................................... 43/43 | ||
total ................................................. 94/94 | ||
@@ -133,0 +159,0 @@ ok |
@@ -64,2 +64,25 @@ var tap = require('tap') | ||
test('Events for DB confirmation and hitting the original seq', function(t) { | ||
var feed = follow(couch.DB, on_change) | ||
var events = { 'confirm':null, 'catchup':null } | ||
feed.on('confirm', function(db) { events.confirm = db }) | ||
feed.on('catchup', function(seq) { events.catchup = seq }) | ||
function on_change(er, ch) { | ||
t.false(er, 'No problem with the feed') | ||
if(ch.seq == 3) { | ||
t.ok(events.confirm, 'Confirm event fired') | ||
t.equal(events.confirm && events.confirm.db_name, 'follow_test', 'Confirm event returned the Couch DB object') | ||
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') | ||
feed.stop() | ||
t.end() | ||
} | ||
} | ||
}) | ||
test('Handle a deleted database', function(t) { | ||
@@ -66,0 +89,0 @@ var feed = follow(couch.DB, function(er, change) { |
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
52582
909
164