Awaiting dynamically supervised tasks

Hi

I am sending out batches of notifications and for this I use Task

I’d like to accomplish something like

notifications
|> Enum.map(&Task.Supervisor.start_child(&1))
|> Enum.map(&Task.await(&1))

Where each child is supervised, and retried a few times if crashes.

But AFAIK, you cannot await tasks started by start_child

Any other way to accomplish something like this?

I think a task supervisor will do this. But you’ll need to change it to transient as it defaults to temporary.

http://elixir-lang.org/docs/stable/elixir/Task.Supervisor.html#async/2

If you leave it temporary then the tasks won’t get restarted.

Though I’m not sure what happens if you’re awaiting a restarted task.

You can’t await on restarted tasks. That’s not possible with Task.Supervisor.

1 Like

What would be the correct way to handle this scenario then when my requirements are that each task should be restarted, if it fails + I want to perform tasks in batches of N (hence the await)