Just like the Event Listener,
we would like to provide a more elegant way to handle these stream-like things called
which allow you to schedule something into the Bukkit's scheduler but control it with the ReactiveX.
To use the scheduler stream, we need to inject the
SchedulerService into our component first.
Then we can call the following functions to get the corresponding streams:
The functions of SchedulerService need to create a task on the thread that you called it,
therefore you should never call
subscribeOn() on these streams, otherwise an exceptions will be thrown.
Cancel a scheduled task
It is so easy to cancel a scheduled task, the stream will automatically cancel the task when the stream being dispose.
Asynchronous task & Back to main thread
Sometimes you may need to run some I/O, networking, or heavy tasks, the server may probably hang if you are running those tasks in the main thread.
The Bukkit way is to create a Asynchronous task, but with ReactiveX, we can switch thread with a easier way.
You must ensure that the API you called is thread-safe when you are not running at the server main thread. The best way to avoid thread bug is switch back to the main thread once your heavy task was done.