Hi Alexandre,

This is how the mapAsync stage works, the parallelism parameter controls
the top number of Futures/CompletionStages the stage should have processing
at once, so when the previous Future/CompletionStage completes and it's
value is emitted downstream it will immediately start the next future.

If you look at the doc of the method it actually even says so, just that it
takes some careful reading to see that:

* '''Backpressures when''' the number of futures reaches the
configured parallelism and the downstream
* backpressures or the first future is not completed


I think we can improve the wording so it is more clear though, I have
opened a ticket for that: https://github.com/akka/akka/issues/22525

Cheers
--
Johan
Akka Team

On Fri, Mar 10, 2017 at 9:50 AM, Alexandre Delegue <
[email protected]> wrote:

> Hi,
>
> should open an issue for this ?
>
> Thanks.
>
>
> Le mardi 7 mars 2017 08:20:35 UTC+1, Alexandre Delegue a écrit :
>>
>> Hi,
>>
>> Executing this code
>>
>> Source.range(1, 4)
>>         .mapAsync(1, e -> CompletableFuture.supplyAsync(() -> {
>>             System.out.println("Num "+e);
>>             return e;
>>         }))
>>         .filter(any -> true)
>>         .take(1)
>>         .runWith(Sink.foreach(e -> { System.out.println("End "+e); }), mat);
>>
>>
>> Will print
>> Num 1
>> End 1
>> Num 2
>>
>> I don't understand why the async call in mapAsync is executed for number
>> 2 while the stream should be completed.
>>
>> This work fine
>>
>> Source.range(1, 4)
>>         .mapAsync(1, e -> CompletableFuture.supplyAsync(() -> {
>>             System.out.println("Num "+e);
>>             return e;
>>         }))
>>         .take(1)
>>         .runWith(Sink.foreach(e -> { System.out.println("End "+e); }), mat);
>>
>>
>> So it seems that the filter method pull next element even if the stream
>> is completed.
>>
>> Any idea? Is there a way to avoid that ?
>>
>> Thanks,
>> Alexandre.
>>
>>
>> --
> >>>>>>>>>> Read the docs: http://akka.io/docs/
> >>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/
> current/additional/faq.html
> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
> ---
> You received this message because you are subscribed to the Google Groups
> "Akka User List" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to