Skip to content

Commit

Permalink
pass function name to handle info if supported
Browse files Browse the repository at this point in the history
  • Loading branch information
andymck committed Apr 8, 2021
1 parent 8d59366 commit ba03e7c
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/grpcbox_stream.erl
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,20 @@ handle_call(ctx, State=#state{ctx=Ctx}) ->
handle_call({ctx, Ctx}, State) ->
{ok, ok, State#state{ctx=Ctx}}.

handle_info(Msg, State=#state{method=#method{module=Module}}) ->
case erlang:function_exported(Module, handle_info, 2) of
true -> Module:handle_info(Msg, State);
false -> State
handle_info(Msg, State=#state{method=#method{module=Module, function=Function}}) ->
%% if the handler module exports handle_info/3, then use that
%% the 3 version passes the invoked RPC which can be used
%% by the handler to accommodate any function specific handling
%% really this is a bespoke use case
%% fall back to handle_info/2 if the /3 is not exported
case erlang:function_exported(Module, handle_info, 3) of
true -> Module:handle_info(Function, Msg, State);
false ->
case erlang:function_exported(Module, handle_info, 2) of
true -> Module:handle_info(Msg, State);
false ->
State
end
end.

add_trailers(Ctx, Trailers=#{}) ->
Expand Down

0 comments on commit ba03e7c

Please sign in to comment.