Problem:

Currently, using Task.Supervisor requires putting the supervisor name itself as 
the first parameter for most of the API functions.

This makes it difficult to pipe into it or use it in Enum.map/2 without using 
sometimes confusing function captures.

Mostly, this makes the async_stream_* functions fairly unintuitive. It’s most 
useful in streaming pipelines but can’t be used in them easily without wrapper 
functions.

Proposal:

Use a “using” pattern similar to the one used in GenServer or even Task itself 
to make it easy to create “wrapper supervisors”.

Something like this…
> defmodule MyTaskSupervisor do
>   use Task.Supervisor
> end
> 
> MyTaskSupervisor.start_link()
> 
> list_stale_files()
> |> MyTaskSupervisor.async_stream_nolink(&File.rm/1)
> |> log_results()

Considerations:

It would probably be useful to accept options for the “using” macro.  At least 
the options to Task.Supervisor.start_link would be useful.

We could also implement a set_dynamic_task_supervisor in the style of Ecto’s 
set_dynamic_repo. This would be most important for testing, where being able to 
run many of these in parallel would be helpful.

—
Jayson Vantuyl

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/F36FEB12-5A0C-4971-B608-9FDAE3C3C612%40gmail.com.

Reply via email to