[erlang-questions] Calling (equivalent of) erlang:send_after/3 from a NIF?

Lukas Larsson lukas@REDACTED
Tue Oct 30 10:37:52 CET 2018

On Mon, Oct 29, 2018 at 5:48 PM Roger Lipscombe <roger@REDACTED>

> I'd like to start a timer in my NIF. It should send a message to an
> Erlang process after a delay. There doesn't appear to be an
> enif_send_after.
> Is there any way to do this?

No, there is no way to do this. One of the reasons this would be difficult
to implement is because it is currently only possible to create timers on
normal schedulers. So that functionality would have to be extended to be
useable from dirty schedulers, which is no small task.

If I were to do what you are after, I would first see if it is fast enough
to setup timers as the nif returns, using a monotonic timestamp to adjust
them for the time it took for the nif to return.

Another idea would be to use timerfd_create and then do a enif_select on
that. Or just roll your own thread, with a small enough number of counters
it should be simple enough.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20181030/5943d23d/attachment.htm>

More information about the erlang-questions mailing list