Skip to content

Are Tasks Connectable? #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
hamiltop opened this issue Aug 19, 2014 · 5 comments
Open

Are Tasks Connectable? #21

hamiltop opened this issue Aug 19, 2014 · 5 comments

Comments

@hamiltop
Copy link
Owner

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)

@hamiltop
Copy link
Owner Author

Tasks can be connectable if we define a task as follows:

  1. Function to execute on a new process
  2. Connect to another process and send that process a message with the result

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.

@josevalim
Copy link

Tasks can also be connectable if we make them follow the same message pattern (probably the notify one) as the GenEvent messages.

@hamiltop
Copy link
Owner Author

hamiltop commented Sep 4, 2014

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.

@josevalim
Copy link

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.

@hamiltop
Copy link
Owner Author

hamiltop commented Sep 5, 2014

We could have the Task process block until connected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants