event-iterator icon indicating copy to clipboard operation
event-iterator copied to clipboard

Disable highwater/lowwater feature

Open timmolendijk opened this issue 3 years ago • 3 comments

I'm trying to use the library without setting any restrictions on buffer size (because if I set restrictions I will have to deal with buffers elsewhere in my code).

I've tried to read the source code (since the docs don't really mention this scenario) and it has left me with a few questions:

  • By default a high water mark of 100 items is set, but does this have any real consequences other than a console warning? I noticed that an isPaused flag is set, but then nothing is truly paused as new events will still be pushed to queue(?)

  • What is the recommended approach for disabling the back pressure (including console warning) altogether? I've tried setting highWaterMark to undefined but this won't override the default parameter value of 100. I figure I could implement highWater with an empty function, but that feels a bit hacky.

Thanks for your work on this project and I hope you will find some time help me out a little bit. Cheers!

timmolendijk avatar Jun 01 '21 17:06 timmolendijk

Looked into this once more and I am drawing the following preliminary conclusions:

  • highWaterMark and lowWaterMark settings do not impact behavior other than that they determine when the highWater and lowWater callbacks will be called, plus a console warning.
  • isPause flag merely exists to prevent repeat calls to those callbacks (plus the console warning).
  • Not using this feature and disabling the console warning can be done by either defining an noop highWater callback or setting highWaterMark to Infinity.

Do these make any sense?

timmolendijk avatar Jun 01 '21 20:06 timmolendijk

I think you're right. In order to deal with high water marks the stream needs to be paused, otherwise the event queue will still fill, potentially until your system memory is exhausted. The documentation section about backpressure should give some context, but of course improvements or further clarifications are welcome: https://github.com/rolftimmermans/event-iterator#backpressure

I do believe it should be possible to disable the warning by setting highWaterMark to undefined? If that does not work I'd consider it a bug. Infinity should work too.

rolftimmermans avatar Jun 02 '21 07:06 rolftimmermans

I do believe it should be possible to disable the warning by setting highWaterMark to undefined? If that does not work I'd consider it a bug. Infinity should work too.

It is a consequence of how JavaScript works:

function getKwargValue({ kwarg = 'value' } = {}) {
  return kwarg;
}

getKwargValue() // => 'value'
getKwargValue({ kwarg: undefined }) // => 'value'

timmolendijk avatar Jun 17 '21 14:06 timmolendijk