From 45037cbccafdd04122bd4ac168f4129d12765208 Mon Sep 17 00:00:00 2001 From: Gregory Burd Date: Tue, 30 Jul 2013 12:53:33 -0400 Subject: [PATCH] Selective receive requires that the ref is created in the scope of the receive. --- src/async_nif.hrl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/async_nif.hrl b/src/async_nif.hrl index 9034d8a..0b415a1 100644 --- a/src/async_nif.hrl +++ b/src/async_nif.hrl @@ -22,7 +22,8 @@ %% ------------------------------------------------------------------- -spec async_nif_enqueue(reference(), function(), [term()]) -> term() | {error, term()}. -async_nif_enqueue(R, F, A) -> +async_nif_enqueue(F, A) -> + R = erlang:make_ref(), case erlang:apply(F, [R|A]) of {ok, enqueued} -> receive @@ -44,4 +45,4 @@ async_nif_enqueue(R, F, A) -> Other end. --define(ASYNC_NIF_CALL(Fun, Args), async_nif_enqueue(erlang:make_ref(), Fun, Args)). +-define(ASYNC_NIF_CALL(Fun, Args), async_nif_enqueue(Fun, Args)).