Permalink
Browse files

only start the periodic timer when update_data is successful

also make sure that dinerl:setup/4 only returns {ok, ...} when
when update_data and timer:apply_interval succeeded
  • Loading branch information...
1 parent d400071 commit 05a6ea36ee8123bd64614ddf507fc0f718f74123 Martin Rehfeld committed Aug 30, 2012
Showing with 9 additions and 4 deletions.
  1. +9 −4 src/dinerl.erl
View
@@ -21,12 +21,17 @@ setup(AccessKeyId, SecretAccessKey, Zone) ->
setup(AccessKeyId, SecretAccessKey, Zone, [{max_connections, 5000}]).
-spec setup(access_key_id(), secret_access_key(), zone(), options()) ->
- {ok, clientarguments()}.
+ {ok, clientarguments()} | {error, any()}.
setup(AccessKeyId, SecretAccessKey, Zone, Options) ->
ets:new(?DINERL_DATA, [named_table, public]),
- R = update_data(AccessKeyId, SecretAccessKey, Zone, Options),
- timer:apply_interval(1000, ?MODULE, update_data, [AccessKeyId, SecretAccessKey, Zone, Options]),
- R.
+ case update_data(AccessKeyId, SecretAccessKey, Zone, Options) of
+ {ok, ClientArgs} ->
+ case timer:apply_interval(1000, ?MODULE, update_data, [AccessKeyId, SecretAccessKey, Zone, Options]) of
+ {ok, _TRef} -> {ok, ClientArgs};
+ Error -> Error
+ end;
+ Error -> Error
+ end.
-spec api(method()) ->result().

0 comments on commit 05a6ea3

Please sign in to comment.