Last active
August 2, 2016 10:56
-
-
Save elbrujohalcon/de7c8495525eb00d58c63c480f101c4f to your computer and use it in GitHub Desktop.
Jaime
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(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