event-iterator
event-iterator copied to clipboard
Disable highwater/lowwater feature
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
toundefined
but this won't override the default parameter value of 100. I figure I could implementhighWater
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!
Looked into this once more and I am drawing the following preliminary conclusions:
-
highWaterMark
andlowWaterMark
settings do not impact behavior other than that they determine when thehighWater
andlowWater
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 settinghighWaterMark
toInfinity
.
Do these make any sense?
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.
I do believe it should be possible to disable the warning by setting
highWaterMark
toundefined
? 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'