It depends on what you mean by controlling the main thread.
If you want to force an arbitrary thread in a specific thread, there is no standard way for it if the thread is not implemented in the library, which allows you to override components that provide asynchrony. In terms of RxJava, it is a Scheduler provided by the Schedulers utility class.
If you want to watch a thread in the main thread, you need to write a lock queue consumer on top of Flow.Subscriber that locks the thread until the queue has elements. This can get complicated, so I will give you the implementation of blockingSubscribe in Reactive4JavaFlow .
If you want to use the main Java thread as Executor / Scheduler , this is even more complicated and requires a similar locking mechanism, as well as some ideas from the threadpool executor. Reactive4JavaFlow has a Scheduler that you can use as a Contractor through: new SubmissionPublisher<>(128, blockingScheduler::schedule) .
source share