Created
October 3, 2011 18:45
-
-
Save vodafon/1259889 to your computer and use it in GitHub Desktop.
loop gen_server
This file contains 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(jobs). | |
-behaviour(gen_server). | |
-export([start_link/0, stop/0, test/0]). | |
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). | |
%% External APIs | |
start_link() -> | |
gen_server:start_link({local, ?MODULE},?MODULE, [], []). | |
stop() -> | |
gen_server:call(?MODULE, stop). | |
test() -> | |
gen_server:call(?MODULE, test). | |
%% Callbacks | |
init([]) -> | |
process_flag(trap_exit, true), | |
{ok, 0, 1000}. | |
handle_call(stop, _From, State) -> | |
{stop, normal, stopped, State}; | |
handle_call(test, _From, State) -> | |
io:format("Test~n"), | |
{reply, ok, State, 1000}; | |
handle_call(_Request, _From, State) -> | |
{reply, ok, State, 1000}. | |
handle_cast(_Request, State) -> | |
{noreply, State, 1000}. | |
handle_info(timeout, State) -> | |
io:format("Print Timeout~n"), | |
{noreply, State, 1000}; | |
handle_info(Info, State) -> | |
io:format("Print ~p~n", [Info]), | |
{noreply, State, 1000}. | |
terminate(_Reason, _State) -> | |
ok. | |
code_change(_OldVsn, State, _Extra) -> | |
{ok, State}. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment