-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Documentation Issue
Sometimes in various "Reactive" projects I see usage of such pattern as
Mono<Void> initiateSideEffects(T arg) {
thirdPartyService.sideEffectOperation(arg)
.subscribe();
yetAnotherService.sideEffectOperation(arg)
.subscribe();
return Mono.empty();
}
I could not find any mention in the Reference documentation regarding such usage of .subscribe(). All instances of .subscribe() in Reference documentation seem to refer to calls from imperative blocking code, to observe Publisher-s behavior.
How safe is such usage from the Reactive code though? What if GC gets to this Disposable and purges it, what happens to underlying Subscription and / or Publisher?
I've asked this question on SO, and the only answer I've got thus far seems to imply that as long as .subscribeOn is used on the Publisher with an appropriate Scheduler, all should be fine.
Can we please have this covered in the Reference documentation too?
Improvement Suggestion
Document "proper" (idiomatic) implementation of "fire-and-forget" scenario in Reactive code (closest analogy in imperative code would be to run a Thread with some Runnable and move on; or an @Async Spring annotation)
Document implication of calling .subscribe() and "forgetting" the returned Disposable, both in assembly-phase code and in subscription-phase code.
Additional context
SO ticket: https://stackoverflow.com/questions/75434622/is-it-safe-to-just-subscribe-to-publishers-in-the-assembly-phase-and-leave-it-at/75445943