Skip to content

Commit

Permalink
Merge pull request #1125 from smallrye/doc/emitOn-warning
Browse files Browse the repository at this point in the history
Warning about potential multi-threading issues when not using emitOn properly
  • Loading branch information
jponge committed Nov 21, 2022
2 parents 60ba371 + 3b165d2 commit fd46bdd
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
7 changes: 6 additions & 1 deletion documentation/docs/guides/emission-threads.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,9 @@ Just pass the _executor_ you want to use.

!!! note

You cannot pass a specific thread, but you can implement a simple `Executor` dispatching on that specific thread, or use a _single threaded executor_.
You cannot pass a specific thread, but you can implement a simple `Executor` dispatching on that specific thread, or use a _single threaded executor_.

!!! warning

Be careful as this operator can lead to concurrency problems with non thread-safe objects such as CDI request-scoped beans.
It might also break reactive-streams semantics with items being emitted concurrently.
5 changes: 5 additions & 0 deletions documentation/docs/guides/emit-on-vs-run-subscription-on.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ sequenceDiagram
Note right of O: On executor thread
```

!!! warning

Be careful as this operator can lead to concurrency problems with non thread-safe objects such as CDI request-scoped beans.
It might also break reactive-streams semantics with items being emitted concurrently.

## The case of runSubscriptionOn

`runSubscriptionOn` applies to the subscription process.
Expand Down
5 changes: 5 additions & 0 deletions documentation/docs/guides/imperative-to-reactive.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,9 @@ While `runSubscriptionOn` runs the subscription on the given executor, `emitOn`

`emitOn` is also available on `Uni`.

!!! warning

Be careful as this operator can lead to concurrency problems with non thread-safe objects such as CDI request-scoped beans.
It might also break reactive-streams semantics with items being emitted concurrently.


4 changes: 4 additions & 0 deletions implementation/src/main/java/io/smallrye/mutiny/Multi.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ default <O> O stage(Function<Multi<T>, O> stage) {
* threading context to switch to a thread from the given executor. Same behavior for failure and completion.
* <p>
* Note that the subscriber is guaranteed to never be called concurrently.
* <p>
* <strong>Be careful as this operator can lead to concurrency problems with non thread-safe objects such as
* CDI request-scoped beans.
* It might also break reactive-streams semantics with items being emitted concurrently.</strong>
*
* @param executor the executor to use, must not be {@code null}
* @return a new {@link Multi}
Expand Down
3 changes: 3 additions & 0 deletions implementation/src/main/java/io/smallrye/mutiny/Uni.java
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,9 @@ default UniAwait<T> awaitUsing(Context context) {
* <p>
* Instead of receiving the {@code item} event on the thread firing the event, this method influences the
* threading context to switch to a thread from the given executor.
* <p>
* <strong>Be careful as this operator can lead to concurrency problems with non thread-safe objects such as
* CDI request-scoped beans.</strong>
*
* @param executor the executor to use, must not be {@code null}
* @return a new {@link Uni}
Expand Down

0 comments on commit fd46bdd

Please sign in to comment.