Integrate newest version which avoids the need for a seperate fun.

This commit is contained in:
Gregory Burd 2013-08-04 17:36:13 -04:00
parent 6d5daab80d
commit 095031a23d

View file

@ -21,27 +21,27 @@
%% %%
%% ------------------------------------------------------------------- %% -------------------------------------------------------------------
-spec async_nif_enqueue(reference(), function(), [term()]) -> term() | {error, term()}. -define(ASYNC_NIF_CALL(Fun, Args),
async_nif_enqueue(R, F, A) -> F = fun(F, T) ->
case erlang:apply(F, [R|A]) of R = erlang:make_ref(),
{ok, enqueued} -> case erlang:apply(F, [R|Args]) of
receive {ok, enqueued} ->
{R, {error, shutdown}=Error} -> receive
%% Work unit was queued, but not executed. {R, {error, shutdown}=Error} ->
Error; %% Work unit was queued, but not executed.
{R, {error, _Reason}=Error} -> Error;
%% Work unit returned an error. {R, {error, _Reason}=Error} ->
Error; %% Work unit returned an error.
{R, Reply} -> Error;
Reply {R, Reply} ->
end; Reply
{error, eagain} -> end;
%% Work unit was not queued, try again. {error, eagain} ->
async_nif_enqueue(R, F, A); SleepyTime = min(30, (T+1)*2),
%{error, enomem} -> timer:sleep(SleepyTime),
%{error, shutdown} -> F(F, SleepyTime);
Other -> Other ->
Other Other
end. end
end,
-define(ASYNC_NIF_CALL(Fun, Args), async_nif_enqueue(erlang:make_ref(), Fun, Args)). F(Fun, 0)).