A fact given by experiments: When a NIF aborted, it will terminate the entire Elixir abnormally, even if a supervisor monitors it.
mix new abort_nif --supcd abort_nif- edit the following files.
mix.exslib/abort_nif/application.exlib/abort_nif.exMakefilelibnif.c
mix deps.getiex -S mix
AbortNif has push/1 and pop/0 functions:
iex(1)> AbortNif.pop()
:empty
iex(2)> AbortNif.push(1)
:ok
iex(3)> AbortNif.push(2)
:ok
iex(4)> AbortNif.pop()
2
iex(5)> AbortNif.pop()
1
iex(6)> AbortNif.pop()
:emptyAbortNif aborts by abort_soft/0 and restart soon by the supervisor.
The state will be empty by restarting:
iex(1)> AbortNif.push(1)
:ok
iex(2)> AbortNif.push(2)
:ok
iex(3)> AbortNif.abort_soft()
:ok
iex(4)> AbortNif.pop()
:emptyAbortNif aborts by abort_hard/0 by NIF, but it will terminate the entire Elixir abnormally, even if the supervisor monitors it.
iex(1)> AbortNif.push(1)
:ok
iex(2)> AbortNif.push(2)
:ok
iex(3)> AbortNif.abort_hard()
zsh: abort iex -S mix
%
%