I wrote a NIF which have function that can take a long time to run. To prevent the scheduler from being overloaded with long running functions (even if marked at dirty), I made my NIF threaded and it sends message back to erlang using enif_send.
I want to make those call synchronous from a “programmer point of view”. Similar to a Process.sleep() call.
I was wondering what was the best approach. To avoid messing with the caller message inbox and to have an isolated process to receive the message, I thought of using something like this:
task = Task.async(fn ->
call_nif(self())
receive do
<wait for nif response>
end
end)
Task.await(task)
Would that be a good approach?






















