Skip to content

Commit

Permalink
Refactor ref
Browse files Browse the repository at this point in the history
  • Loading branch information
lpgauth committed Aug 7, 2015
1 parent 3b9a9c3 commit 00ed3a8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
3 changes: 1 addition & 2 deletions include/shackle.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
-record(cast, {
client :: client(),
pid :: pid(),
pool_name :: pool_name(),
ref :: reference(),
reply :: term(),
request :: term(),
request_id :: request_id(),
timestamp :: erlang:timestamp(),
timing = [] :: [pos_integer()]
}).
Expand Down
17 changes: 6 additions & 11 deletions src/shackle.erl
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,15 @@ cast(PoolName, Request, Pid) ->
Timestamp = os:timestamp(),
case shackle_pool:server(PoolName) of
{ok, Client, Server} ->
Ref = make_ref(),
RequestId = {PoolName, make_ref()},
Server ! #cast {
client = Client,
pid = Pid,
pool_name = PoolName,
ref = Ref,
request = Request,
request_id = RequestId,
timestamp = Timestamp
},
{ok, {PoolName, Ref}};
{ok, RequestId};
{error, backlog_full} ->
{error, backlog_full}
end.
Expand All @@ -75,17 +74,13 @@ receive_response(RequestId) ->
-spec receive_response(request_id(), timeout()) ->
{ok, term()} | {error, term()}.

receive_response({PoolName, Ref} = RequestId, Timeout) ->
receive_response({PoolName, _} = RequestId, Timeout) ->
Timestamp = os:timestamp(),
receive
#cast {
pool_name = PoolName,
ref = Ref
} = Cast ->

#cast {request_id = RequestId} = Cast ->
handle_timing(Cast),
Cast#cast.reply;
#cast {pool_name = PoolName} ->
#cast {request_id = {PoolName, _}} ->
Timeout2 = shackle_utils:timeout(Timeout, Timestamp),
receive_response(RequestId, Timeout2)
after Timeout ->
Expand Down

0 comments on commit 00ed3a8

Please sign in to comment.