aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2010-10-14 14:42:04 +0200
committerAlexander Sulfrian <alexander@sulfrian.net>2010-10-14 14:42:04 +0200
commit8b8794d0db80e0d79e38c28146ca0d3d60764839 (patch)
treeb645cb72443c6cefcf17f3bdbee37f0b68ec0c17
parent693c92e8dddf6295599ad3e530572e9ff57cb0a5 (diff)
downloaderlang-8b8794d0db80e0d79e38c28146ca0d3d60764839.tar.gz
erlang-8b8794d0db80e0d79e38c28146ca0d3d60764839.tar.xz
erlang-8b8794d0db80e0d79e38c28146ca0d3d60764839.zip
code cleanup
-rw-r--r--server/client.erl44
1 files changed, 16 insertions, 28 deletions
diff --git a/server/client.erl b/server/client.erl
index 333df4a..cb6504e 100644
--- a/server/client.erl
+++ b/server/client.erl
@@ -14,43 +14,31 @@ start(Node) ->
{error, {unknown_error, Why}}
end.
+execute(Client, F) ->
+ %% execute F() with error handling
+ %% (sends error message on exception)
+ try F() of
+ Result ->
+ Client ! {ok, Result}
+ catch
+ _: Why ->
+ Client ! {error, Why}
+ end.
+
loop(Client) ->
+ %% mainloop for client modul in server
receive
list ->
- try media:all() of
- Result ->
- Client ! {ok, Result}
- catch
- _: Why ->
- Client ! {error, Why}
- end;
+ execute(Client, fun() -> media:all() end);
get_votes ->
- try media:getVotes(Client) of
- Result ->
- Client ! {ok, Result}
- catch
- _: Why ->
- Client ! {error, Why}
- end;
+ execute(Client, fun() -> media:getVotes(Client) end);
{vote, Artist, Title} ->
- try media:vote(Artist, Title) of
- Result ->
- Client ! {ok, Result}
- catch
- _: Why ->
- Client ! {error, Why}
- end;
+ execute(Client, fun() -> media:vote(Artist, Title) end);
{devote, Artist, Title} ->
- try media:devote(Artist, Title) of
- Result ->
- Client ! {ok, Result}
- catch
- _: Why ->
- Client ! {error, Why}
- end;
+ execute(Client, fun() -> media:devote(Artist, Title) end);
Cmd ->
Client ! {error, {unknown_command, Cmd}}