How can I get the same effect with Reactor instead of java's scheduler?
Executors.newSingleThreadScheduledExecutor()
.scheduleAtFixedRate(() -> counter.set(0) , computeDelay(), computePeriod(), TimeUnit.MILLISECONDS)
I tried
Flux
.interval(Duration.ofMillis(computeDelay()), Duration.ofMinutes(RESET_PERIOD_MINUTES))
.doOnNext( counter.set(0))
.subscribe())
But It generates uneccessary Long value. I found some Schedulers in Flux API but while trying to create one I got Disposable object, then I have no idea what should do with it
you found both options. the Flux.interval is useful to compose with other operators. it emits longs that represents each tick, because Flux has to emit something
Scheduler.schedulePeriodically is the other option, pretty much equivalent to ExecutorService.scheduleAtFixedRate, except it returns a Disposable rather than a Future of Void. (in both case you'd use that to cancel the work)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With