M
M
Maxim Barulin2014-10-16 17:53:00
Erlang
Maxim Barulin, 2014-10-16 17:53:00

Erlang. How to transfer a thread from one process to another?

Good day, Habr!
There is an OTP application in it, several supervisors, let it be A and B.
Supervisor A spawns a worker Aa.
Supervisor B spawns worker Ba upon request from Aa.
How to transfer the control flow from B to Ba, so that Aa waits for a response from Ba, and not from B?
3ed9ead58329458fb1dec78a1aab595b.png
As one of the options, I'm considering re-architecting the application, but this will be an extreme case.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2014-10-16
@Slavenin999

gen_server has
handle_call(Msg, From, State) ->
PidBa ! { Msg, From },
{ noreply, State };
this From is a pointer to the one who is waiting.
That. you in Ba must somehow pass this From.
Ba can then reply:
gen_server:reply(From, Answer).
The supervisor itself does not contain such functionality. You need to use an intermediate process and send messages to it, and it will sort out where to send it next.
PS handle_call is called with gen_server:call(Pid, Msg, Timeout).
You can read more in detail here:
www.erlang.org/doc/man/gen_server.html
and in a more popular form here:
learnyousomeerlang.com/clients-and-servers
or in Russian around this:
https://github.com/dyp2000/Russian-Armstrong-Erlang

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question