GithubHelp home page GithubHelp logo

Comments (5)

akarnokd avatar akarnokd commented on May 17, 2024

Gem 22 handles the case when there is a subscriber but it hasn't called request() yet. fromCallable runs immediately but defers the emission. This gem defers the execution because the front just emits only when requested, then that value triggers the execution of the callable

from reactive-streams-commons.

dsyer avatar dsyer commented on May 17, 2024

Gem 22 link: #21 (comment)

from reactive-streams-commons.

dsyer avatar dsyer commented on May 17, 2024

Here's the code from Gem 22 (with a concrete supplier and a log instead of using sysout):

        Callable<String> callable = () -> "foo";
        Mono.just("irrelevant").log().map(unused -> {
            try {
                return callable.call();
            } catch (Exception ex) {
                throw Exceptions.bubble(ex); // or Exceptions.propagate(ex)
            }
        }).subscribe(log::info, Throwable::printStackTrace);

and here's the output:

10:06:25.504 [main] INFO reactor.core.publisher.FluxLog -  onSubscribe(reactor.core.util.ScalarSubscription@5442a311)
10:06:25.506 [main] INFO reactor.core.publisher.FluxLog -  request(unbounded)
10:06:25.506 [main] INFO reactor.core.publisher.FluxLog -  onNext(irrelevant)
10:06:25.506 [main] INFO com.example.MonoFeaturesTests - foo
10:06:25.506 [main] INFO reactor.core.publisher.FluxLog -  onComplete()

Here's the vanilla fromCallable() (as I understood Gem 22 this should be different)

        Mono.fromCallable(callable).log().subscribe(log::info, Throwable::printStackTrace);

and the output:

10:05:13.317 [main] INFO reactor.core.publisher.FluxLog -  onSubscribe(reactor.core.subscriber.DeferredScalarSubscriber@1794d431)
10:05:13.318 [main] INFO reactor.core.publisher.FluxLog -  request(unbounded)
10:05:13.318 [main] INFO reactor.core.publisher.FluxLog -  onNext(foo)
10:05:13.318 [main] INFO com.example.MonoFeaturesTests - foo
10:05:13.318 [main] INFO reactor.core.publisher.FluxLog -  onComplete()

What's the difference?

from reactive-streams-commons.

akarnokd avatar akarnokd commented on May 17, 2024

Updated the gem to show the effect if the request is actually delayed.

from reactive-streams-commons.

dsyer avatar dsyer commented on May 17, 2024

I see, thanks.

from reactive-streams-commons.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.