From 0b05c03224e9abd367597ba09aa291083a466a7b Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Thu, 14 Oct 2010 11:30:22 +0200 Subject: removed code duplication --- client/client.erl | 34 ++++++++-------------------------- 1 file 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}; -- cgit v1.2.3