Skip to content

Instantly share code, notes, and snippets.

@elbrujohalcon
Last active August 2, 2016 10:56
Show Gist options
  • Save elbrujohalcon/de7c8495525eb00d58c63c480f101c4f to your computer and use it in GitHub Desktop.
Save elbrujohalcon/de7c8495525eb00d58c63c480f101c4f to your computer and use it in GitHub Desktop.
Jaime
-module(jaime).
-behaviour(gen_server).
-export([ start/0
, carry/1
, deliver/0
, trip/0
]).
-export([ init/1
, terminate/2
, handle_info/2
, handle_call/3
, handle_cast/2
, code_change/3
]).
start() -> gen_server:start({local, ?MODULE}, ?MODULE, [], []).
carry(Stuff) -> gen_server:cast(?MODULE, {carry, Stuff}).
deliver() -> gen_server:call(?MODULE, deliver).
trip() -> gen_server:call(?MODULE, trip).
init([]) -> {ok, []}.
handle_cast({carry, Stuff}, Tray) -> {noreply, [Stuff | Tray]}.
handle_call(deliver, _From, Tray) -> {reply, Tray, []};
handle_call(trip, _From, []) -> throw(empty_tray);
handle_call(trip, _From, [Stuff|Tray]) -> throw({reply, Stuff, Tray}).
handle_info(_Info, State) -> {noreply, State}.
code_change(_OldVsn, State, _Extra) -> {ok, State}.
terminate(_Reason, _Tray) -> ok.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment