debounce
, throttleFirst
, and throttleLast
are most conspicuously absent from Project Reactor's Flux. Do they have any counterparts?
What are the Flux equivalents of debounce, throttleFirst, and throttleLast
Asked Answered
The sample
operators are the once relating to the behavior you're searching for.
sampleTimeout
could be used as debounce
.
sampleFirst
could be used as throttleFirst
.
sample
could be used as throttleLast
.
I've been struggling to understand how to use sampleTimeout
to do a debounce
so I though I would put it here in case someone else is looking for this:
The would be equivalent to a debounce
of 200ms
myFlux.sampleTimeout(u -> Mono.empty().delaySubscription(Duration.ofMillis(200)))
That would do a fixed sampling every 200ms. So a window would never last more than 200ms whereas with what I did the windows will last as long as you have elements being received less than 200ms apart from each others. The marbles in the documentation may help. –
Lightness
Thanks. OK, I want it to emit every window, just not more often, so
sample(Duration)
is fine for my use case. –
Bigley © 2022 - 2024 — McMap. All rights reserved.
myFlux.sample(Duration.ofMillis(200))
and so far I haven't managed it - what do you think the difference is? – Bigley