ADR 0002: Native runtime and operation ownership
View SourceStatus
Accepted for ROADMAP001.
Decision
A loaded iroh_beam_nif owns one multithreaded Tokio runtime. Normal-scheduler
NIF calls may perform bounded validation and atomic/resource operations, but may
not bind, wait, perform network I/O, or call Runtime::block_on.
Async calls use this protocol:
- Elixir creates an operation reference and supplies its caller PID.
- Native code creates a monitored operation resource and submits a future.
- Completion sends
{IrohBeam.Native, reference, result}exactly once. - Explicit cancellation, caller death, or timeout marks the operation cancelled and wakes its future; cancelled operations do not send late results.
- Elixir translates native maps into
%IrohBeam.Error{}and suppresses any already-cancelled reference.
Resources are internally synchronized. Future endpoint, connection, and stream resources have explicit asynchronous close operations. Drop callbacks only abort; they never wait for runtime work.