{{ preamble }}std::thread::Builder::new()
.stack_size(32 * 1024 * 1024)
.spawn(move || {
// ~keep 16 MiB: the spawning thread's 32 MiB only covers `block_on`; tasks the
// future spawns run on tokio workers, whose ~2 MB default stack can overflow on a
// deep extraction future (a nested archive member, a multi-stage OCR pipeline),
// aborting the process with SIGBUS instead of raising a catchable panic.
const NIF_RUNTIME_STACK_SIZE_BYTES: usize = 16 * 1024 * 1024;
let rt = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.thread_stack_size(NIF_RUNTIME_STACK_SIZE_BYTES)
.build()
.map_err(|e| e.to_string())?;
let result = rt.block_on(async { {{ core_call }}.await });
Ok::<_, String>({{ result_wrap }})
})
.map_err(|e| e.to_string())?
.join()
.map_err(|_| "thread panicked".to_string())?