pub fn spawn<'a, S, F>(env: Env<'a>, thread_fn: F) where
    F: for<'b> FnOnce(Env<'b>) -> Term<'b> + Send + UnwindSafe + 'static,
    S: JobSpawner
Expand description

Implements threaded NIFs.

This spawns a thread that calls the given closure thread_fn. When the closure returns, the thread sends its return value back to the calling process. If the closure panics, an {error, Reason} tuple is sent instead.

Note that the thread creates a new Env and passes it to the closure, so the closure runs under a separate environment, not under env.