Integrate newest version which avoids the need for a seperate fun.
This commit is contained in:
parent
6d5daab80d
commit
095031a23d
1 changed files with 24 additions and 24 deletions
|
@ -21,27 +21,27 @@
|
|||
%%
|
||||
%% -------------------------------------------------------------------
|
||||
|
||||
-spec async_nif_enqueue(reference(), function(), [term()]) -> term() | {error, term()}.
|
||||
async_nif_enqueue(R, F, A) ->
|
||||
case erlang:apply(F, [R|A]) of
|
||||
{ok, enqueued} ->
|
||||
receive
|
||||
{R, {error, shutdown}=Error} ->
|
||||
%% Work unit was queued, but not executed.
|
||||
Error;
|
||||
{R, {error, _Reason}=Error} ->
|
||||
%% Work unit returned an error.
|
||||
Error;
|
||||
{R, Reply} ->
|
||||
Reply
|
||||
end;
|
||||
{error, eagain} ->
|
||||
%% Work unit was not queued, try again.
|
||||
async_nif_enqueue(R, F, A);
|
||||
%{error, enomem} ->
|
||||
%{error, shutdown} ->
|
||||
Other ->
|
||||
Other
|
||||
end.
|
||||
|
||||
-define(ASYNC_NIF_CALL(Fun, Args), async_nif_enqueue(erlang:make_ref(), Fun, Args)).
|
||||
-define(ASYNC_NIF_CALL(Fun, Args),
|
||||
F = fun(F, T) ->
|
||||
R = erlang:make_ref(),
|
||||
case erlang:apply(F, [R|Args]) of
|
||||
{ok, enqueued} ->
|
||||
receive
|
||||
{R, {error, shutdown}=Error} ->
|
||||
%% Work unit was queued, but not executed.
|
||||
Error;
|
||||
{R, {error, _Reason}=Error} ->
|
||||
%% Work unit returned an error.
|
||||
Error;
|
||||
{R, Reply} ->
|
||||
Reply
|
||||
end;
|
||||
{error, eagain} ->
|
||||
SleepyTime = min(30, (T+1)*2),
|
||||
timer:sleep(SleepyTime),
|
||||
F(F, SleepyTime);
|
||||
Other ->
|
||||
Other
|
||||
end
|
||||
end,
|
||||
F(Fun, 0)).
|
||||
|
|
Loading…
Reference in a new issue