Reputation: 469
I'm confused by prefetch
parameter from concatMap
which basically sounds like MAX_CONCURRENCY
.
prefetch: the number of elements to prefetch from the current Observable
Q1: Does it mean to prefetch elements from Observable
for mapping and then subscribe one at a time in order?
e.g, the docs for concatMapSingle
is pretty clear:
Maps the upstream items into SingleSources and subscribes to them one after the other succeeds, emits their success values or terminates immediately if either this Observable or the current inner SingleSource fail.
Q2: Is it true that doc for concatMap
can be reworded as:
Maps the upstream items into ObservableSources and subscribes to them one after the other completes?
The original version of a doc for concatMap
:
Returns a new Observable that emits items resulting from applying a function that you supply to each item emitted by the source ObservableSource, where that function returns an ObservableSource, and then emitting the items that result from concatenating those resulting ObservableSources.
i.e., the following lines are basically the same (in terms of MAX_CONCURRENCY
)?
int MAX_CONCURRENCY = 1;
Observable.just(1, 2, 3).flatMap(num -> Observable.just(num), false, MAX_CONCURRENCY);
Observable.just(1, 2, 3).concatMap(num -> Observable.just(num));
Upvotes: 0
Views: 1299
Reputation: 69997
Q1: Does it mean to prefetch elements from Observable for mapping and then subscribe one at a time in order?
In the current implementation of concatMap
, upstream items are prefetched but are not mapped until the previous inner source completed (or it is the very first item). The inner sources are run one-by-one.
Q2: Is it true that doc for concatMap can be reworded as:
I'd also mention the error behavior in the first sentence just like with concatMapSingle
. PR welcome.
Some of the older javadocs are worded a bit convoluted, the newer ones are more snappy. Those old ones annoy me too, but unless they would need some expansion - due to increased StackOverflow questions/misunderstandings about them - I tend to leave them alone.
the following lines are basically the same (in terms of MAX_CONCURRENCY)?
With Observable
s, there is no backpressure so both concatMap
and flatMap
have to queue up upstream items until they are ready to be mapped and subscribed to. concatMap
's prefetch
hint should be more like capacityHint
as it is used for sizing the internal queue holding the extra values.
Upvotes: 1