From 05c8c615efb57e6e6f55d0c1ab18352734624c53 Mon Sep 17 00:00:00 2001 From: Gregory Burd Date: Thu, 1 Aug 2013 10:02:21 -0400 Subject: [PATCH] I think the make_ref() needs to be within the fun()'s context to trigger selective receive optimization in the beam's runtime. --- src/async_nif.hrl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/async_nif.hrl b/src/async_nif.hrl index d7b5bee..192ee36 100644 --- a/src/async_nif.hrl +++ b/src/async_nif.hrl @@ -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)).