I think the make_ref() needs to be within the fun()'s context to trigger selective receive optimization in the beam's runtime.
This commit is contained in:
parent
f153509409
commit
05c8c615ef
1 changed files with 4 additions and 3 deletions
|
@ -22,7 +22,8 @@
|
|||
%% -------------------------------------------------------------------
|
||||
|
||||
-define(ASYNC_NIF_CALL(Fun, Args),
|
||||
F = fun(F, A, R, T) ->
|
||||
F = fun(F, A, T) ->
|
||||
R = erlang:make_ref(),
|
||||
case erlang:apply(F, [R|A]) of
|
||||
{ok, enqueued} ->
|
||||
receive
|
||||
|
@ -38,9 +39,9 @@
|
|||
{error, eagain} ->
|
||||
SleepyTime = min(30, (T+1)*2),
|
||||
timer:sleep(SleepyTime),
|
||||
F(F, A, R, SleepyTime);
|
||||
F(F, A, SleepyTime);
|
||||
Other ->
|
||||
Other
|
||||
end
|
||||
end,
|
||||
F(Fun, Args, erlang:make_ref(), 1)).
|
||||
F(Fun, Args, 0)).
|
||||
|
|
Loading…
Reference in a new issue