Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changesReader.get doesn't call the 'end' callback #315

Open
Delink-D opened this issue Dec 20, 2022 · 1 comment
Open

changesReader.get doesn't call the 'end' callback #315

Delink-D opened this issue Dec 20, 2022 · 1 comment

Comments

@Delink-D
Copy link

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:
@jbgtmartin
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants