Skip to content

Instantly share code, notes, and snippets.

@qrilka
Created June 9, 2011 10:35
Show Gist options
  • Select an option

  • Save qrilka/1016498 to your computer and use it in GitHub Desktop.

Select an option

Save qrilka/1016498 to your computer and use it in GitHub Desktop.
-module(test).
-behaviour(gen_fsm).
-export([start_link/0]).
-export([init/1, checking/2,
handle_event/3, handle_sync_event/4, handle_info/3,
terminate/3, code_change/4]).
-define(TIMEOUT, 2000).
start_link() ->
gen_fsm:start_link({local, ?MODULE}, ?MODULE, [], []).
%% ------------------------------------------------------------------
init([]) ->
gen_fsm:start_timer(?TIMEOUT, []),
{ok, checking, []}.
checking({timeout, _Ref, _Msg}, State) ->
io:format("~p: I'm realy a timer!~n", [erlang:time()]),
gen_fsm:start_timer(?TIMEOUT, []),
{next_state, checking, State}.
handle_event(_Event, SN, SD) ->
{next_state, SN, SD}.
handle_sync_event(_Event, _From, SN, SD) ->
{next_state, SN, SD}.
handle_info(_Info, SN, SD) ->
{next_state, SN, SD}.
terminate(_Reason, _SN, _SD) ->
ok.
code_change(_OldVsn, SN, SD, _Extra) ->
{ok, SN, SD}.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment