Hey, I have a question related to Supervisor
, Stream
and Flow
.
Let’s make a simplest example:
defmodule Example do
def process(list_element), do: list_element * list_element
end
list = [1, 2, 3, 4, 5]
In normal case we could call Enum.map(list, &Example.process/1)
or &Stream.map(&Example.process/1)
.
But it’s only a simple example. In more complicated processing I need to supervise each of &Example.process/1
call and run multiple (with sorting order) calls (multithread).
So what I’m looking for is API like this:
# restart each element that fails
stream = supervise(list, &Example.process/1)
# get first 3 entries, supervise and process each of them
first_result = Enum.take(stream, 3)
second_result =
stream
|> Enum.map(&SomeModule.save_element/1)
|> Enum.uniq
IO.puts Enum.count(second_result == 1) and List.first(second_result) == :ok