Created
July 19, 2012 18:52
-
-
Save devnoo/3145962 to your computer and use it in GitHub Desktop.
seven languages in seven weeks erlang day 3
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(doctor). | |
-behaviour(supervisor). | |
-export([start/0]). | |
-export([init/1]). | |
start() -> | |
supervisor:start_link({local, doctor}, doctor, []). | |
init(_Args) -> | |
{ok, {{one_for_one, 1, 60}, | |
[{roulette, {roulette, start, []}, | |
permanent, brutal_kill, worker, [roulette]}]}}. |
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
bla |
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
bla |
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(monitor). | |
-behaviour(supervisor). | |
-export([start/0]). | |
-export([init/1]). | |
start() -> | |
supervisor:start_link({local, monitor}, monitor, []). | |
init(_Args) -> | |
{ok, {{one_for_one, 1, 60}, | |
[{translator, {translate_service, start, []}, | |
permanent, brutal_kill, worker, [translate_service]}]}}. |
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(roulette). | |
-behaviour(gen_server). | |
-export([start/0, init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). | |
start() -> | |
gen_server:start_link({local, roulette}, roulette, [], []). | |
init(_Args) -> | |
{ok, 0}. | |
handle_call(Number, _From, State) -> | |
Response = case Number of | |
3 -> io:format("bang"), terminate("bang", bang); | |
_ -> "click" | |
end, | |
{reply, Response , State}. | |
handle_cast(_Message, State) -> {reply, State}. | |
handle_info(_Message, State) -> {reply, State}. | |
terminate(_Reason, _State) -> io:format("Stopping because: ~p~n", [_Reason]), ok. | |
code_change(_OldState, _NewState, _Extra) -> {ok, _NewState}. |
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
c(monitor). | |
c(translate_service). | |
monitor:start(). | |
translate_service:translate(translator,"casa"). | |
translate_service:translate(translator,"apagas"). | |
translate_service:translate(translator,"casa"). |
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
ba |
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(translate_service). | |
-behaviour(gen_server). | |
-export([start/0, init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). | |
-export([translate/1]). | |
start() -> | |
gen_server:start_link({local, translator}, translate_service, [], []). | |
init(_Args) -> | |
{ok, 0}. | |
handle_call(WordToTranslate, _From, State) -> | |
Response = case WordToTranslate of | |
"casa" -> "house"; | |
"blanca" -> "white"; | |
"apagas" -> exit({translator, die, at, erlang:time()}); | |
_ -> "Don't understand" | |
end, | |
{reply, Response , State}. | |
translate(Word) -> | |
gen_server:call(translator, Word). | |
handle_cast(_Message, State) -> {reply, State}. | |
handle_info(_Message, State) -> {reply, State}. | |
terminate(_Reason, _State) -> io:format("Stopping because: ~p~n", [_Reason]), ok. | |
code_change(_OldState, _NewState, _Extra) -> {ok, _NewState}. | |
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(uber_doctor). | |
-behaviour(supervisor). | |
-export([start/0]). | |
-export([init/1]). | |
-export([terminate/0]). | |
start() -> | |
supervisor:start_link({local, uberdoctor}, uber_doctor, []). | |
init(_Args) -> | |
{ok, {{one_for_one, 1, 60}, | |
[{doctor, {doctor, start, []}, | |
permanent, infinity, supervisor, [doctor]}]}}. | |
terminate() -> | |
supervisor:terminate("bla", bla). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment