Permalink
Browse files

Provide a rexi:cast that uses erlang:send/2

Sometimes we want to have workers avoid deferring their casts to a
temporary process. This can lead to message pileups on the distribution
control sockets.

BugzID: 13469
  • Loading branch information...
1 parent 42df8e4 commit c6b77781da5cf48917c3bb45901176d56725194f @davisp davisp committed Apr 17, 2012
Showing with 18 additions and 1 deletion.
  1. +18 −1 src/rexi.erl
View
@@ -14,7 +14,7 @@
-module(rexi).
-export([start/0, stop/0, restart/0]).
--export([cast/2, cast/3, kill/2]).
+-export([cast/2, cast/3, cast/4, kill/2]).
-export([reply/1, sync_reply/1, sync_reply/2]).
-export([async_server_call/2, async_server_call/3]).
-export([get_errors/0, get_last_error/0, set_error_limit/1]).
@@ -63,6 +63,23 @@ cast(Node, Caller, MFA) ->
rexi_utils:send({?SERVER, Node}, Msg),
Ref.
+%% @doc Executes apply(M, F, A) on Node.
+%% This version accepts a sync option which uses the erlang:send/2 call
+%% directly in process instead of deferring to a spawned process if
+%% erlang:send/2 were to block. If the sync option is omitted this call
+%% is identical to cast/3.
+-spec cast(node(), pid(), {atom(), atom(), list()}, [atom()]) -> reference().
+cast(Node, Caller, MFA, Options) ->
+ case lists:member(sync, Options) of
+ true ->
+ Ref = make_ref(),
+ Msg = cast_msg({doit, {Caller, Ref}, get(nonce), MFA}),
+ erlang:send({?SERVER, Node}, Msg),
+ Ref;
+ false ->
+ cast(Node, Caller, MFA)
+ end.
+
%% @doc Sends an async kill signal to the remote process associated with Ref.
%% No rexi_EXIT message will be sent.
-spec kill(node(), reference()) -> ok.

0 comments on commit c6b7778

Please sign in to comment.