Skip to content

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

@adammilnesmith

Description

@adammilnesmith

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    ❓need-triageThis issue needs triage, hasn't been looked at by a team member yet

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions