Handle_info callback not called

Hi all,

My handle_info callback for GenServer is not called.
Here is the code:

On line 18 in init I send myself a :kickoff message but the callback is not invoked.
The same code was working when my top-level module used the Application behaviour.
But I needed command-line arguments and restructured the code - I parse my arguments in the CLI module and pass them to the Application module which just calls Supervisor.start_link. And it stopped working and I can’t figure out why.

Hello and welcome…

handle_info/2, not 3! but You pass 3 parameters… it’s not going to work :slight_smile:

I use tuple in such case, like {:kickoff, params}

Process.send_after(self(), {:kickoff, 0})
...
def handle_info({:kickoff, workers_count}, state) do
...
end

BTW, there is also handle_continue You can benefit from… in init.

1 Like

The 0 in send_after is not intended as a message - its the timeout.
I want to just finish initialization and handle the :kickoff message immediately after that, using the workers_count (which is my state) to launch this number of workers.

On a side note, recent Elixir and Erlang versions ship with “handle_continue” which you may want to use instead of custom kickoff message sent from init. Not much of functional change but a nice syntax designed to do initialization specifically after process is started.

2 Likes

So handle_continue is for You…

BTW I think You are mistaken about timeout meaning, it’s the time You allow for response to comeback… before returning a timeout.

1 Like

Yes, I picked the wrong word. But handle_continue solved the problem, thanks.