Lethi
Lethi

Reputation: 1177

Give name to child process

I have supervisor which spawns dynamic child using spawn_link. When I create new child:

create_my_child().

it return:

{ok, <0.324.0>}

so everything happy. I try to assign variable to child from console:

{ok,X} = create_my_child()

I get error saying:

exception error: no match of right hand side value

and says:

{supervisor,do_start_child_i,3

I done all difficult work, is possible to do this for child process?

Upvotes: 1

Views: 117

Answers (1)

chops
chops

Reputation: 2612

If you're doing all this in the console, then X is already bound to return Pid of the first spawn_link call, and the subsequent attempt to match {ok, X} with create_my_child() call fails with the "no match of right hand side" error.

In Erlang, variables are not mutable, so you cannot re-assign X after it already has a value. In the console, you could do f() to the clear the shell's variables, but the easier solution is to simply bind do a different variable (ie X2)

Upvotes: 2

Related Questions