In these past few year I've found myself needing to execute several async
tasks (mostly around getting remote resources) in scripts, and wanting to
do something in the ones that fail
With the current implementation of async_stream, there is no way to know
which ones failed, as the output would look like the following:
```
[1, 2, 3, 4]
|> Task.async_stream(
  fn entry ->
    if entry == 3, do: :timer.sleep(2000)
    entry * entry
  end,
  timeout: 1000,
  on_timeout: :exit_task
)
|> Enum.to_list()
[ok: 1, ok: 4, exit: :timeout, ok: 16]
```
That would force me to get creative with stream Zip, or hand roll my own
solution.

@vtm in the elixir slack pointed me to the commit
https://github.com/elixir-lang/elixir/commit/c94327cc4 in wich such
functionality was removed because of backwards compatibility.
And the commit that introduced it was
https://github.com/elixir-lang/elixir/commit/6c1fe08a676f1cacb7ee66dd56251b8a48a02d63#diff-0e81c1197153b352765d1d43ca57817901d19813a220e95a2cd2e70f3cfaa279R376
when adding the :ordered parameter to Task.async_stream

Would you accept a PR about exposing this functionality again, but behind a
opt-in new parameter that is false by default in order to keep backwards
compatibility.

Using the previous example, it would look something like:
1, 2, 3, 4]
|> Task.async_stream(
  ...,
  timeout: 1000,
  on_timeout: :exit_task_with_value,
)
|> Enum.to_list()
[ok: 1, ok: 4, {:exit :timeout, 3}, ok: 16]
```
I'm not sold in the flag :exit_task_with_value, it could be a separate
parameter as well, as long as it's opt_in

Thanks
*_________________________________________________________**_**____*
*Juan* -
*No todo el oro reluce.....Ni todo errante anda perdido*
*¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯**¯**¯**¯¯¯¯*

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/CAPx9ufN-kdNYuAJri_z9pxQ-0yopvSdNUVBLpZ1G6fTHPk1BDw%40mail.gmail.com.

Reply via email to