Created
September 26, 2017 03:01
-
-
Save elbrujohalcon/9b2ab087c8a8eaf373284ecbf47548e3 to your computer and use it in GitHub Desktop.
Maybe Server v4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(maybe_server). | |
-behaviour(gen_server). | |
-export([start_link/0, sleep/0, stop/0]). | |
-export([init/1, terminate/2, handle_call/3, handle_cast/2]). | |
%% EXTERNAL API ------------------------------------------------------------------------------------ | |
start_link() -> gen_server:start_link({local, ?MODULE}, ?MODULE, #{}, [{debug, [log, trace]}]). | |
sleep() -> gen_server:cast(?MODULE, something). | |
stop() -> gen_server:stop(?MODULE). | |
%% CALLBACKS --------------------------------------------------------------------------------------- | |
init(#{}) -> | |
error_logger:info_msg("Server ~p starting.~n", [self()]), | |
process_flag(trap_exit, true), | |
{ok, #{}}. | |
terminate(Reason, _State) -> | |
error_logger:info_msg("Server ~p terminating with reason ~p~n", [self(), Reason]). | |
handle_cast(_Msg, State) -> | |
timer:sleep(30000), | |
{noreply, State}. | |
%% UNUSED CALLBACKS -------------------------------------------------------------------------------- | |
handle_call(_Msg, _From, State) -> {noreply, State}. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment