reactor-addons icon indicating copy to clipboard operation
reactor-addons copied to clipboard

RxJava3Adapter.singleToMono() doesn't cascade dispose() calls up the chain to the RxJava disposable

Open adammilnesmith opened this issue 2 years ago • 0 comments

RxJava3Adapter.singleToMono() doesn't cascade dispose() calls up the chain to the RxJava disposable.

Expected Behavior

dispose() calls should cascade up the chain to the RxJava Single disposable.

Actual Behavior

dispose() calls are not cascaded up the chain to the RxJava Single disposable.

Steps to Reproduce

This test will fail for singleToMono:

@Test
public void singleToMonoCancel() {
	final AtomicBoolean disposeWasCalled = new AtomicBoolean(false);
	Mono<Integer> m = Single.<Integer>never()
			.doOnDispose(() -> disposeWasCalled.set(true))
			.to(RxJava3Adapter::singleToMono);
	m.subscribe().dispose();
	assertTrue(disposeWasCalled.get());
}

It's worth noting that this passes for maybeToMono:

@Test
public void maybeToMonoCancel() {
	final AtomicBoolean disposeWasCalled = new AtomicBoolean(false);
	Mono<Integer> m = Maybe.<Integer>never()
			.doOnDispose(() -> disposeWasCalled.set(true))
			.to(RxJava3Adapter::maybeToMono);
	m.subscribe().dispose();
	assertTrue(disposeWasCalled.get());
}

Possible Solution

Add the following to SingleAsMonoSubscriber matching MaybeAsMonoObserver

            @Override
            public void cancel() {
                super.cancel();
                d.dispose();
            }

Your Environment

  • Reactor version(s) used: v3.5.0
  • Other relevant libraries versions: RxJava 2 and 3

adammilnesmith avatar Feb 28 '23 17:02 adammilnesmith