What's the difference between emitOn and runSubscriptionOn?

Learn how to control threads subscription threads.

emitOn vs. runSubscriptionOn

The emitOn and runSubscriptionOn are 2 operators influencing on which threads the event are dispatched. However, they target different types of events and different directions.

emitOn takes events coming from upstream (items, completion, failure) and replays them downstream on a thread from the given executor. Consequently, it affects where the subsequent operators execute (until another emitOn is used):

Multi.createFrom().items(this::retrieveItemsFromSource)
        .emitOn(executor)
        .onItem().transform(this::applySomeOperation)
        .subscribe().with(
        item -> System.out.println("Item: " + item),
        Throwable::printStackTrace,
        () -> completed.set(true)
);

The previous code produces the following sequence:

Diagram

runSubscriptionOn applies to the subscription process. It requests the upstream to run its subscription (call of the subscribe method on its own upstream) on a thread from the given executor:

Multi.createFrom().items(() -> {
    // called on a thread from the executor
    return retrieveItemsFromSource();
})
        .onItem().transform(this::applySomeOperation)
        .runSubscriptionOn(executor)
        .subscribe().with(
        item -> System.out.println("Item: " + item),
        Throwable::printStackTrace,
        () -> completed.set(true)
);

So, if we consider the previous code snippet, it produces the following sequence:

Diagram