-
Notifications
You must be signed in to change notification settings - Fork 331
Add flatMapWithConcurrencyLimit, flatMapConcat, bufferingThrottle, holdWhen #324
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
Conversation
spec/BaconSpec.coffee
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delay => minimumInterval ?
|
|
|
How would minIntervalWithBuffer(200,1000) sound? Pretty verbose. |
|
Bug found: 116cf76 |
|
I might go for |
|
In case you want to try out this code, you can dl it here |
|
There's a stack overflow issue yet to be solved. Fiddle here: http://jsfiddle.net/865yn/1/ |
|
The stack overflow occurs here because flatMapWithConcurrencyLimit flushes its buffer using a recursive algorithm. This can be fixed. |
|
Well, now the test passes, but if chunk size is increased still, there will be another stack overflow. I don't think the problem has much to do with this particular PR, but is in fact a more general issue when dealing with "big" accumulation, where javascript recursion fails. It could also be said that buffering thousands of events and then flushing them at once is usually not good business anyway. I vote we ship this stuff in now and consider the "big accumulation" issue separately. I added a test in 1cbd648 for finding the maximum supported "fold length" which is slightly above 5000 iterations on node. |
|
Oops, it seems I fixed it. Added support for |
|
flatMapWithConcurrencyLimit is exactly what we need. Using it from the branch currently, any idea if it will be in master soon? |
|
Yeah, this PR had been hanging around for a while. I just rebased it against master to make it mergeable again. |
|
Need to update readme (readme-src.coffee, then grunt readme) to include all the changed, then we can merge. Who's up for the task? Oh, and naming |
|
I can update the readme. |
|
Another comment: should we invert the |
|
Here's a docs: feel free to cherry-pick and edit: phadej@111a5ff |
|
Thanks @phadej, I included your docs! What about I appreciate @phadej's suggestion of inverting |
|
@raimohanska: one way is to scan thru plumbing vocabulary: http://en.wikipedia.org/wiki/Control_valves for a new name... which btw makes me think about, how these are then related: var a = stream.filter(f);
var b = stream.controlValve(stream.map(f)); |
|
Same kinda relationship as with |
|
Ah, wrote the last post too fast: Let us have stream.filter = (p) ->
@controlValue(@map((x) -> if p(x) then Pass else Drop))
stream.holdWhen = (valve) ->
@controlValue(valve.map((x) -> if x then Pass else Hold)) |
|
@phadej you're right in that |
|
wat wat, it's in master! |
|
So I went with |
Related to #318 I implemented a
flatMapWithConcurrencyLimitmethod that's a flatMap variant that limits the number of open spawned streams. It buffers incoming events to keep from losing any input.Then I applied the new combinator to create
flatMapConcatthat's just a shorthand for the previous with limit==1. The default flatMap implementation can be thought of "flatMapMerge" because it merges the output of spawned streams.Finally, I implemented
rateLimitas a one-liner on top offlatMapConcat. This is the combinator that was requested in #317 and once implemented in #82 as "limitThroughPut".And then I added one more thing
holdWhenthat's the same thing asbufferWhilein #300, also based onflatMapConcat. I chose this name not to confuse this method with the "buffer" family of methods or the takeWhile/skipWhile methods.DON'T MERGE YET!
TODO: still naming..