couchdb-nano icon indicating copy to clipboard operation
couchdb-nano copied to clipboard

`changesReader.get` doesn't call the 'end' callback

Open Delink-D opened this issue 2 years ago • 1 comments

Expected Behavior

On call of changesReader.get it's expected that the request should pull changes till the last change then on('end' should be called

Current Behavior

Currently on call of changesReader.get({ includeDocs: true, since: changesSince, batchSize: 500 }) the changes are pulled but on('end', () => {...}) never gets called. So I can't tell when all the changes have been pulled.

Your Environment

  • Version used: 10.1.0
  • Browser Name and version: N/A
  • Running in node app: 16.17.0
  • Operating System and version (desktop or mobile):
  • Link to your project:

Delink-D avatar Dec 20 '22 07:12 Delink-D

I guess that the issue lies in changesreader.js, when batchSize > 1:

// stop on empty batch
if (self.stopOnEmptyChanges && data && typeof data.results !== 'undefined' && data.results.length === 0) {
  self.continue = false
}

The reader is supposed to emit end when self.continue === false. But when the batch size is more than 1, the last batch will likely contain some elements (almost never 0), and thus the condition data.results.length === 0 will never be met. Maybe we should set self.continue to false when data.pending === 0 as well?

jbgtmartin avatar May 31 '24 10:05 jbgtmartin