spring-attic / reactive-streams-commons

A joint research effort for building highly optimized Reactive-Streams compliant operators.
Apache License 2.0
357 stars 51 forks source link

Clarification on the Scheduler.Worker.schedule contract #30

Closed agentgt closed 5 years ago

agentgt commented 5 years ago

The Scheduler.Worker#schedule javadoc says:


    /**
     * Creates a worker of this Scheduler that executed task in a strict
     * FIFO order, guaranteed non-concurrently with each other.
     * <p>
     * Once the Worker is no longer in use, one should call shutdown() on it to
     * release any resources the particular Scheduler may have used.
     * 
     * <p>Tasks scheduled with this worker run in FIFO order and strictly non-concurrently, but
     * there are no ordering guarantees between different Workers created from the same
     * Scheduler.
     * 
     * @return the Worker instance.
     */

The FIFO order seems to be preserved in all of the code examples but I don't understand the semantics being used for "strictly non-concurrently".

For example it appears ExecutorServiceScheduler will have Workers that will run tasks concurrently unless a single thread executor is used.

In other Reactive Streams implementations that have a scheduler aka rxjava there is no mention of that guarantee.

Is there some implementation logic I'm missing or am I misunderstanding the doc?

akarnokd commented 5 years ago

Please read the Scheduler JavaDocs.

The so-called Scheduler.Workers of a Scheduler can be created via the createWorker() method which allow the scheduling of multiple Runnable tasks in an isolated manner. Runnable tasks scheduled on a Worker are guaranteed to be executed sequentially and in a non-overlapping fashion. Non-delayed Runnable tasks are guaranteed to execute in a First-In-First-Out order but their execution may be interleaved with delayed tasks. In addition, outstanding or running tasks can be cancelled together via Disposable.dispose() without affecting any other Worker instances of the same Scheduler.

agentgt commented 5 years ago

Yes but that is the RxJava documentation of which I'm familiar with and is far more clear. I just thought it might be worthwhile to put something similar in this project.

Edit: what I meant by rxjava "not mentioning" meaning it does not have that guarantee... not that it doesn't explain the interleaving... sorry my mistake for saying that. RxJava has excellent documentation.

akarnokd commented 5 years ago

This project is no longer developed and we applied the knowledge and further clarifications in the respective libraries long ago.