Skip to content

Mono.zipWith argument is subscribed on empty mono #1031

@Delorien84

Description

@Delorien84

I have notice when apply "zipWith" operator on empty mono, the argument is subscribed even if the original mono is empty. See "zipWith" test bellow. The test failed. The workaround for me is to use "zipWhen" operator.

Expected behavior

Mono.zipWith with empty mono will not subscribe the argument.

Actual behavior

Mono.zipWtih with empty mono subscribes the argument.

Steps to reproduce

 @Test
    public void zipWith() { // this test failed
        AtomicInteger i = new AtomicInteger(0);
        Tuple2<Integer, Integer> res = Mono.just(1)
                .filter(x -> x == 0)
                .<Integer>zipWith(Mono.create(s -> {
                    i.incrementAndGet();
                    s.success(5);
                }))
                .block();
        Assert.assertNull(res);
        Assert.assertEquals(0, i.get());
    }

    @Test
    public void zipWhen() {
        AtomicInteger i = new AtomicInteger(0);

        Tuple2<Integer, Integer> res = Mono.just(1)
                .filter(x -> x == 0)
                .<Integer>zipWhen(x -> Mono.create(s -> {
                    i.incrementAndGet();
                    s.success(5);
                }))
                .block();
        Assert.assertNull(res);
        Assert.assertEquals(0, i.get());
    }

Reactor Core version

3.1.2-RELEASE

JVM version (e.g. java -version)

java version "1.8.0_152"
Java(TM) SE Runtime Environment (build 1.8.0_152-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.152-b16, mixed mode)

OS version (e.g. uname -a)

Linux stiller2 4.14.13-1-ARCH #1 SMP PREEMPT Wed Jan 10 11:14:50 UTC 2018 x86_64 GNU/Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    status/declinedWe feel we shouldn't currently apply this change/suggestion

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions