-
Notifications
You must be signed in to change notification settings - Fork 97
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
Add bufferWithTimeout() and bufferWithInterval(). #227
Comments
If you want to use it with Update: Ah sorry, misunderstood which library uses |
I thought about something like |
Yeah, if we subscribe to the same stream twice here is how it can be done: var stream = Kefir.stream(em => {
setTimeout(() => {em.value(0); em.value(0); em.value(0)}, 0)
setTimeout(() => {em.value(150)}, 150)
setTimeout(() => {em.value(200)}, 200)
setTimeout(() => {em.value(250)}, 250)
setTimeout(() => {em.value(300)}, 300)
setTimeout(() => {em.value(350)}, 350)
setTimeout(() => {em.value(400); em.end()}, 400)
})
stream.bufferBy(stream.flatMapFirst(() => Kefir.later(100))).log() |
Thanks, this works great. Does it make sense to add the functions outlined above to emphasize the difference between interval and timeout?
BTW: In TypeScript (and I think Flow) it is |
Not sure yet if we should add the methods. We will have too many buffering methods with slightly different behaviour. To my taste we already have a bit too many. Maybe we should keep this open and wait for more demand.
We don't have If Flow/TypeScript don't allow to omit second argument maybe it's for the best actually. Kefir doesn't have a special support for it neither, it just works as if |
+1
At least TypeScript allows this and it is quite common. -export declare function interval<T>(interval: number, value: T): Stream<T, void>
+export declare function interval<T>(interval: number, value?: T): Stream<T, void> |
Yea, I just not 100% sure about Flow/TypeScript, but I'll merge the PR if you create one. |
Highland uses
setTimeout()
and Kefir usessetInterval()
for the batch/buffer with time (illustrated below). It would be nice to have both functions in Kefir, with a distinctive name.Using
highlandStream.batchWithTimeOrCount(100 /*ms/*, Infinity)
:Using
kefirStream.bufferWithTimeOrCount(100 /*ms*/, Infinity)
:The text was updated successfully, but these errors were encountered: