diff options
author | Alexander Sulfrian <alexander@sulfrian.net> | 2010-10-14 11:30:22 +0200 |
---|---|---|
committer | Alexander Sulfrian <alexander@sulfrian.net> | 2010-10-14 11:30:22 +0200 |
commit | 0b05c03224e9abd367597ba09aa291083a466a7b (patch) | |
tree | f8a5176b74bd4472f83734766442d3cb2e4541f4 | |
parent | 40d28960b17bfe6b09fabdcfc0555c9db9cd5971 (diff) | |
download | erlang-0b05c03224e9abd367597ba09aa291083a466a7b.tar.gz erlang-0b05c03224e9abd367597ba09aa291083a466a7b.tar.xz erlang-0b05c03224e9abd367597ba09aa291083a466a7b.zip |
removed code duplication
-rw-r--r-- | client/client.erl | 34 |
1 files changed, 8 insertions, 26 deletions
diff --git a/client/client.erl b/client/client.erl index aab0b4e..ec44401 100644 --- a/client/client.erl +++ b/client/client.erl @@ -58,41 +58,23 @@ list() -> {error, not_logged_in} end. -handle(list, Server) -> - Server ! list, +send_to_server(Cmd, Server) -> + Server ! cmd, receive {ok, Msg} -> {Msg, Server}; Msg -> {Msg, Server} - end; + end. +handle(list, Server) -> + send_to_server(list, Server); handle(get_votes, Server) -> - Server ! get_votes, - receive - {ok, Msg} -> - {Msg, Server}; - Msg -> - {Msg, Server} - end; - + send_to_server(get_votes, Server); handle({vote, Artist, Title}, Server) -> - Server ! {vote, Artist, Title}, - receive - {ok, Msg} -> - {Msg, Server}; - Msg -> - {Msg, Server} - end; - + send_to_server({vote, Artist, Title}, Server); handle({devote, Artist, Title}, Server) -> - Server ! {vote, Artist, Title}, - receive - {ok, Msg} -> - {Msg, Server}; - Msg -> - {Msg, Server} - end; + send_to_server({devote, Artist, Title}, Server); handle({change_state, NewState}, _) -> {{ok}, NewState}; |