pub fn apply_elixir_fun<'a>(
    env: Env<'a>,
    pid_or_name: Term<'a>,
    fun: Term<'a>,
    parameters: Term<'a>
) -> Result<Term<'a>, Error>
Expand description

Will run fun with the parameters parameters on the process indicated by pid_or_name.

On success, returns an Ok result whose content is a term which might be one of:

  • {:ok, some_term} on a successfull function call.
  • {:error, {:exception, some_exception}} if the function raised an exception.
  • {:error, {:exit, exit_message}} if an exit was caught.
  • {:error, {:throw, value}} if a value was thrown.

Raises an ArgumentError (e.g. returns Err(Error::BadArg) on the Rust side) if fun is not a function or parameters is not a list.

Notes

  • Be sure to register any NIF that calls this function as a ‘Dirty CPU NIF’! (by using #[rustler::nif(schedule = "DirtyCpu")]). This is important for two reasons:
    1. calling back into Elixir might indeed take quite some time.
    2. we want to prevent schedulers to wait for themselves, which might otherwise sometimes happen.