This concerns the changesReader API of the couchdb-nano library.
Expected Behavior
I would expect the following code to wait 10 seconds and then return a batch of messages from the last position in the changes feed. So if I updated the DB 5 times within that 10 second timeout I would expect to see: "a batch of 5 changes has arrived" after 10 seconds.
messages.changesReader
.start({ timeout: 10000 })
.on('batch', (batch) => {
console.log('a batch of', batch.length, 'changes has arrived');
}).on('error', (e) => {
console.error('error', e);
});
Current Behavior
What is happening is that no batching is taking place. Every time I update the database within that timeout I immediately get the log "a batch of 1 changes has arrived".
Have I missed something obvious or misunderstood how nano's batching works?
There is no problem with nano. The super short answer is to use
getbut even then your interpretation oftimeout(which seems much more like a pause or accumulate) is flawed.Consider the documentation for
startOK that's clear,
startpolls "indefinitely". Thetimeoutdocumentation statesSo
timeoutdoes not apply when usingstart. Yes, the documentation could be less puzzling.When does
timeoutapply? Here's thegetmethod documentationIn other words if X milliseconds transpire without a change event,
getpolling concludes with theendevent (maybespoolas well - I didn't test).Consider the node script below, which demonstrates the behavior with
get. Theendevent will occur 10 seconds after the last batch event fires.Here's an example output
Note the script ended 10 seconds (the timeout) after the last event.
If one were to replace
getwithstart, theendevent never fires.Update
I thought it important to add that the feed responses can vary depending on the disposition of the server and client. For example, a subsequent run the above script produced compact batch responses: