Skip to content

Instantly share code, notes, and snippets.

@IgorKarymov
Created March 22, 2012 13:58
Show Gist options
  • Save IgorKarymov/2158498 to your computer and use it in GitHub Desktop.
Save IgorKarymov/2158498 to your computer and use it in GitHub Desktop.
with_worker(Fun) when is_function(Fun, 1) ->
{IsFromDict, Worker} =
case get($riak_pool_worker) of
undefined ->
Worker = riak_pool:get_worker(),
put($riak_pool_worker, Worker),
{false, Worker};
Worker ->
{true, Worker}
end,
try
Fun(Worker)
after
case IsFromDict of
true -> pass;
false ->
erase($riak_pool_worker),
catch(riak_pool:free_worker(Worker))
end
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment