[JAVA-3398] Consider Publisher<Void> instead of Publisher<Success> Created: 17/Jul/17  Updated: 28/Oct/23  Resolved: 08/Nov/19

Status: Closed
Project: Java Driver
Component/s: Reactive Streams
Affects Version/s: None
Fix Version/s: 4.0.0

Type: Improvement Priority: Major - P3
Reporter: Mark Paluch Assignee: Ross Lawley
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to JAVA-4303 Improve map/flatmap of Publisher[Void] Closed
Backwards Compatibility: Major Change

 Description   

MongoDB driver returns Publisher<Success> for operations that do not return a value and which would be represented with void in an imperative API.

Reactive API's are inherently event-oriented (onNext|onComplete|onError signals) and do not require emission of a placeholder data element to signal successful completion. A successful termination without emitting an element would be the idiomatic approach for a Reactive Streams API. Each composition library has its own strategy how to represent the absence of elements/completion:

  • Project Reactor: Mono<Void>
  • RxJava 2: Completable type (manifestation via type system)
  • Akka Streams: CompletableFuture<Done> (using Java 8's type and Done to prevent null)

It would be great if a future version of the Reactive Streams driver would adapt to Publisher<Void>.

Reference:



 Comments   
Comment by Githook User [ 15/Jan/20 ]

Author:

{'name': 'Ross Lawley', 'username': 'rozza', 'email': 'ross.lawley@gmail.com'}

Message: Publisher<Success> => Publisher<Void>

Removed the Success enum to represent a successful operation. Idioms
have changed since the 1.0 version of the MongoDB Reactive Streams driver
and although null is an invalid value for a publisher. A Publisher<Void>
has come to represent empty publisher that only signals when a publisher has
either completed or errored.

Removed the Scala type alias of Completed to Void. This brings the
implementation inline with the driver it wraps.

JAVA-3398
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/24780d53705de06d511af7e5cae18081449c9401

Comment by Ross Lawley [ 23/Oct/19 ]

PR: https://github.com/rozza/mongo-java-driver/pull/333

Comment by Jeffrey Yemin [ 04/Feb/19 ]

Consider for when we merge Reactive Streams into Java Driver 4.0.

Comment by Mark Paluch [ 17/Jul/17 ]

Hey ross.lawley,

The request wasn't intended for a minor version increment (1.x version) but rather a major release. Indeed, your driver was created in a time with high uncertainty about the ideal patterns.

Emission of a null value is not allowed by the Reactive Streams spec so no one would expect a null value to be emitted.
In fact, Publisher<Void> expresses that no value is qualified for emission. Expectations are set to a publisher that just signals completion (successful/with an error). In terms of interoperability, Void is a common base type and Publisher<Void> are meanwhile well-known.

RxJava 2 has a rich type-system that isn't entirely based on the Reactive Streams spec, only Flowable is a Publisher.

Comment by Ross Lawley [ 17/Jul/17 ]

Hi mp911de,

Thanks for the ticket. Unfortunately, this would be an API break and would require a major release. Back when the reactive streams API was still in beta, there wasn't a clear consensus on what pattern should be used for a successful operation. If I recall correctly, Publisher<Void> was explicitly frowned upon at the time; as results couldn't be null it was deemed invalid.

It seems more patterns have come from usage overtime and a wider consensus has evolved, and two new Publisher types have evolved: Completable and Single Publishers. Essentially, the Publisher<Success> is comparable with the differing Completable strategies and achieve the same aim.

Ross

Generated at Thu Feb 08 08:59:31 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.