Skip to content

Instantly share code, notes, and snippets.

@ishankhare07
Created November 28, 2017 16:41
Show Gist options
  • Save ishankhare07/f3763411ddd56eea87b1d15be72fef7c to your computer and use it in GitHub Desktop.
Save ishankhare07/f3763411ddd56eea87b1d15be72fef7c to your computer and use it in GitHub Desktop.
a timer in erlang
-module(timer).
-export([start/2, cancle/1]).
start(Time, Fun) ->
spawn(fun() -> timer(Time, Fun) end)).
cancle(Pid) -> Pid ! cancle.
timer(Time, Fun) ->
receive
cancle ->
void
after Time ->
Fun()
end.
@ishankhare07
Copy link
Author

call as

Pid = start(5000, fun() -> io:format("timer event~n") end).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment