apple / servicetalk

A networking framework that evolves with your application
https://docs.servicetalk.io
Apache License 2.0
915 stars 180 forks source link

`Amb` operators for `Single` and `Completable` should respect reactive contract 2.3 #3040

Closed daschl closed 1 month ago

daschl commented 1 month ago

Motivation

Reactive Streams rule 2.3 mandates, that Subscriber.onComplete() and Subscriber.onError(Throwable t) MUST NOT call any methods on the Subscription or the Publisher.

Our current amb operator implementation also performs a cancellation on the Single that just completed, which violates the rule.

Modifications

This changeset modifies the amb operator in a way that all but the one Single which got a termination signal (through onNext or onError) will get the cancellation propagated.

The test suite is enhanced to cover this scenario, both for ambWith as well as the static amb factory methods. Since the Completable also converts to Single underneath, the functionality is transitively available as well.

Result

The amb* operator variants adhere to reactive streams 2.3 rule.

daschl commented 1 month ago

I'll follow up with the docs in a separate pr.