# Running Task.async_stream/3 for side effects

Calling `Task.async_stream/3` does not start any tasks:

```elixir
Task.async_stream(customer_ids, &Mailer.deliver_invoice/1)
```

It returns a lazy stream. The tasks start only when something enumerates that stream, so ignoring the return value silently skips every delivery.

If you only need the side effects, run the entire stream:

```elixir
customer_ids
|> Task.async_stream(&Mailer.deliver_invoice/1, ordered: false)
|> Stream.run()
```

Use `Enum.to_list/1` or another `Enum` function when you need the `{:ok, value}` results. Adding another `Stream` step does not start the work, because the pipeline is still lazy.

Mind you, stopping consumption early can start more tasks than results you keep. Put `Stream.take/2` before `Task.async_stream/3` when that matters.

https://hexdocs.pm/elixir/Task.html#async_stream/3


---

Created by: almirsarajcic
Date: September 16, 2026
URL: https://elixirdrops.net/d/HjTWfkFL
