Mint.HTTP.controlling_process
controlling_process
, go back to Mint.HTTP module for more information.
Specs
controlling_process(t(), pid()) :: {:ok, t()} | {:error, Mint.Types.error()}
Changes the controlling process of the given connection to new_pid
.
The controlling process is a concept that comes from the Erlang TCP and SSL implementations. The controlling process of a connection is the process that started the connection and that receives the messages for that connection. You can change the controlling process of a connection through this function.
This function also takes care of "transferring" all the connection messages that are in the mailbox of the current controlling process to the new controlling process.
Remember that the connection is a data structure, so if you
change the controlling process it doesn't mean you "transferred" the
connection data structure itself to the other process, which you have
to do manually (for example by sending the connection data structure to the
new controlling process). If you do that, be careful of race conditions
and be sure to retrieve the connection in the new controlling process
before accepting connection messages in the new controlling process.
In fact, this function is guaranteed to return the connection unchanged,
so you are free to ignore the connection entry returned in {:ok, conn}
.
Examples
send(new_pid, {:conn, conn})
{:ok, conn} = Mint.HTTP.controlling_process(conn, new_pid)
# In the "new_pid" process
receive do
{:conn, conn} ->
# Will receive connection messages.
end