invoke vs map in Mutinity java reactive code

63 Views Asked by At

i not understand why the code:

 Multi.createFrom().ticks().every(Duration.ofSeconds(10)).onItem().invoke(
            x -> return "example"
        ).subscribe().with(System.out::println);

-> print: 1,2,3,.. (every 10 sec)

not produce the same output like this:

Multi.createFrom().ticks().every(Duration.ofSeconds(10)).map(
            x -> return "example"
        ).subscribe().with(System.out::println);

-> print example,example .. (every 10 sec)

why? It's a quarkus project with dependecy:

    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-mutiny</artifactId>
    </dependency>

thanks

1

There are 1 best solutions below

0
Clement On

The invoke method is called when an item (or failure if used after onFailure()) arrives but does not send its result downstream. It's just to peek at the event, not to change it.

The map method is called when an item arrives and transforms that event. The result of the method is sent downstream.

References: