Reactor in JavaFX applications?

246 views
Skip to first unread message

Paul Houle

unread,
Apr 12, 2016, 1:59:24 PM4/12/16
to reactor-framework
At the moment I am messing around with JavaFX and learned very quickly that asynchronous coding is the way to go and I'd like to be doing it with the reactor framework.

It seems the main requirement is that user interface changes be made from a specific thread,  and you can schedule things to run in said thread by calling

Platform.runLater(Runnable that)

How do I encapsulate so that I can send events there in a Reactor application?  Any other things I should know if I mix react and JavaFX?

Stephane Maldini

unread,
Apr 17, 2016, 9:00:27 AM4/17/16
to Paul Houle, reactor-framework
There should be a way to do that with the new Scheduler interface. We'll come with a guide to wrap any scheduler. We are compiling this list of trick in https://github.com/reactor/reactive-streams-commons/issues/21 btw, and that's one of them to come. Also item #2 can be related to that.

Anyhow with a Scheduler, it's a matter of returning a Worker that simply does Platform.runLater e.g. :

Worker fxWorker = runnable -> Platform.runLater(runnable);
Scheduler fx = Worker worker -> fxWorker;

someFlux.publishOn(fxWorker).doOnNext(insidePlatformThread);

--
You received this message because you are subscribed to the Google Groups "reactor-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to reactor-framew...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Stephane Maldini | Reactor Project Lead, Spring Engineering | London | Pivotal

Stephane Maldini

unread,
Apr 17, 2016, 9:03:46 AM4/17/16
to Paul Houle, reactor-framework
Scheduler is in snapshot btw and scheduled for imminent M3. Right now in M2 it looks like :

Consumer<Runnable> fxWorker = runnable -> Platform.runLater(runnable);
Callable<Consumer<Runnable> fx = Consumer<Runnable> worker -> fxWorker;

someFlux.dispatchOn(fxWorker).doOnNext(insidePlatformThread);

As you can see we just gave a name to these slightly too much generic and meaningless plain java types for the context and dispatchOn has been renamed publishOn (breaking change). It's logged under https://github.com/reactor/reactor-core/milestones/2.5.0.M3 description.
Reply all
Reply to author
Forward
0 new messages