Skip to content

Instantly share code, notes, and snippets.

@vlasenkoalexey
Created April 21, 2017 07:04
Show Gist options
  • Save vlasenkoalexey/1836d2c7f60d2bae8878c6cac780ae84 to your computer and use it in GitHub Desktop.
Save vlasenkoalexey/1836d2c7f60d2bae8878c6cac780ae84 to your computer and use it in GitHub Desktop.
-module(frequency_supervisor).
-export([start/0,stop/0]).
-export([init/0]).
start() ->
register(frequency_supervisor, spawn(frequency_supervisor, init, [])).
stop() ->
frequency_supervisor ! stop.
init() ->
process_flag(trap_exit, true),
FrequencyPid = startFrequencyServer(),
loop(FrequencyPid).
startFrequencyServer() ->
FrequencyPid = spawn_link(frequency,init, []),
register(frequency, FrequencyPid),
FrequencyPid.
loop(FrequencyPid) ->
receive
stop ->
io:format("Supervisor stopped\r\n");
{'EXIT', FrequencyPid, _Reason} ->
NewPid = startFrequencyServer(),
loop(NewPid)
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment