Open hamiltop opened 10 years ago
Tasks can be connectable if we define a task as follows:
The current tasks fit into this idea where #2 is specified (or implied) at launch. The alternative is to launch the task without #2 specified and upon completion the task will wait for connection to a receiving process.
Tasks can also be connectable if we make them follow the same message pattern (probably the notify
one) as the GenEvent messages.
Would we allow changing the target of an already launched task? That's what being connectable means to me:
event = GenEvent.start_link
stream = GenEvent.stream(event)
spawn_link fn ->
stream |> Enum.each &IO.puts/1
end
...
task = Task.async( fn -> "hi" end )
Connectable.connect(task, event)
Should result in "hi" being printed to the screen.
Ah, I see what you mean. That would be tricky as the task would likely be already done and sent to the caller. We could change how tasks work but that would increase their overhead. Interesting enough, I was thinking the connectable protocol was always about connecting to self (self would always be the second argument). GenEvent is just more flexible.
We could have the Task process block until connected.
Should tasks be connectable? Is there another construct that looks similar to a task that should be?
If we provide a default implementation for Connectable that supports Streams, then a connectable task would look exactly like
Stream.once(fun)