ReactFX
ReactFX copied to clipboard
how to pause
How do I pause and resume using Timer ?
I followed your approach in http://tomasmikula.github.io/blog/2014/06/04/timers-in-javafx-and-reactfx.html
In javafx, I can do
Timeline autosaveTimer = new Timeline(
new KeyFrame(Duration.seconds(60 * MINUTES),
ae -> masterClock.setSaveSim(DEFAULT)));
At some point I have to call autosaveTimer().pause()
to pause
and later call autosaveTimer().play()
to resume
In ReactFX, I do the following
Timer autosaveTimer = FxTimer.runLater(
java.time.Duration.ofMinutes(60 * MINUTES),
() -> masterClock.setSaveSim(DEFAULT)));
I notice there is a stop() and restart() for Timer
but I don't want to stop autosaveTimer completely and restart from the beginning of MINUTES. I want to resume from whatever MINUTES has elapsed.
Is there a pause() and resume() that I can call ?
Hmm I think currently there is no implementation which satisfy your case. For me I would think there should be something similar to:
EventStreams.ticks(Duration.ofMinutes(MINUTES))
There is already the possibility to create a pasuable or suppressible stream but thats only related to the stream itself not to the ticks or whatever so the ticks can't be paused.
Why not reimplement the FXTimer class with pause functionality in your own code base? It's using Timeline
underneath, so you can use that class' pause
method.