Question

I have gen_server in my erlang code. And when i try to run it the next code after this don't work. For example:

.......
my_server:start_link().
io:format("AAAAAAAAAAAAAAAAAAA"),
.....

Now io:format/1 don't work. And if i run gen_server with spawn:

......
spawn(fun() -> my_server:start_link() end)
io:format("AAAAAAAAAAAAAAAAA")
......

Now io:format worked. Why?

Thank you.

Was it helpful?

Solution

I assume the start_link function in your my_server module calls the gen_server:start_link/3 or gen_server:start_link/4 function.

The gen_server:start_link will in turn call the init function of your my_server module. I guess your init function is a blocking call which is the reason why your initial code piece doesn't return.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top