summaryrefslogtreecommitdiff
path: root/src/worker_pool_worker.erl
diff options
context:
space:
mode:
authorMatthias Radestock <matthias@lshift.net>2010-04-09 17:12:37 +0100
committerMatthias Radestock <matthias@lshift.net>2010-04-09 17:12:37 +0100
commit2db1402bf3bf6b1ffe80aa655eb24c0bbd5e4d7f (patch)
treece41763ee4f81ca5e5c7a3808c197562ed0020a2 /src/worker_pool_worker.erl
parente367a2ecb372af75b234ecd0c2b601dc1f6d7575 (diff)
downloadrabbitmq-server-2db1402bf3bf6b1ffe80aa655eb24c0bbd5e4d7f.tar.gz
add worker_pook:submit_async/1
This was on the todo list and got cherry-picked from the bug21673 branch.
Diffstat (limited to 'src/worker_pool_worker.erl')
-rw-r--r--src/worker_pool_worker.erl12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/worker_pool_worker.erl b/src/worker_pool_worker.erl
index 3bfcc2d9..d3a48119 100644
--- a/src/worker_pool_worker.erl
+++ b/src/worker_pool_worker.erl
@@ -33,7 +33,7 @@
-behaviour(gen_server2).
--export([start_link/1, submit/2, run/1]).
+-export([start_link/1, submit/2, submit_async/2, run/1]).
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).
@@ -44,6 +44,8 @@
-spec(start_link/1 :: (any()) -> {'ok', pid()} | 'ignore' | {'error', any()}).
-spec(submit/2 :: (pid(), fun (() -> A) | {atom(), atom(), [any()]}) -> A).
+-spec(submit_async/2 ::
+ (pid(), fun (() -> any()) | {atom(), atom(), [any()]}) -> 'ok').
-endif.
@@ -60,6 +62,9 @@ start_link(WId) ->
submit(Pid, Fun) ->
gen_server2:call(Pid, {submit, Fun}, infinity).
+submit_async(Pid, Fun) ->
+ gen_server2:cast(Pid, {submit_async, Fun}).
+
init([WId]) ->
ok = worker_pool:idle(WId),
put(worker_pool_worker, true),
@@ -74,6 +79,11 @@ handle_call({submit, Fun}, From, WId) ->
handle_call(Msg, _From, State) ->
{stop, {unexpected_call, Msg}, State}.
+handle_cast({submit_async, Fun}, WId) ->
+ run(Fun),
+ ok = worker_pool:idle(WId),
+ {noreply, WId, hibernate};
+
handle_cast(Msg, State) ->
{stop, {unexpected_cast, Msg}, State}.