From 8b8794d0db80e0d79e38c28146ca0d3d60764839 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Thu, 14 Oct 2010 14:42:04 +0200 Subject: code cleanup --- server/client.erl | 44 ++++++++++++++++---------------------------- 1 file changed, 16 insertions(+), 28 deletions(-) (limited to 'server') 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}} -- cgit v1.2.3