Comments (5)
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.
Gem 22 link: #21 (comment)
from reactive-streams-commons.
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.
Updated the gem to show the effect if the request is actually delayed.
from reactive-streams-commons.
I see, thanks.
from reactive-streams-commons.
Related Issues (20)
- Expand Macro-Fusion paths
- Expand Micro-Fusion ( Back-Fusion and ConditionalSubscriber )
- Add PatitionPublisher and PublisherPartition
- Review and Mark Unbounded Operators
- Add IndexedQueue contract to optimize draining paths
- Explore timed microbatch operators
- Explore Backpressurable#getCapacity optimizations
- Make GroupBy and future partitioning operator store-agnostic HOT 3
- Use shaded dependency on JCTools instead of copy and paste HOT 7
- Unbounded FlatMap with slow consumer HOT 1
- 101 Reactive Gems (working title) HOT 22
- Reactive puzzlers (working title) HOT 2
- Question: Using Reactor streams HOT 3
- Fusing subscribeOn with upstream HOT 8
- Clarification on the Scheduler.Worker.schedule contract HOT 3
- Throttling on leading and trailing edge HOT 11
- Add PublisherIndexOf
- Add PublisherEvery HOT 1
- Expand Micro-Fusion (Front Fusion)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reactive-streams-commons.