Ferricstore.Bitcask.Async (ferricstore v0.4.0)

Copy Markdown View Source

Safe waiter for Tokio-backed async NIF calls.

Async NIFs send :tokio_complete to the pid they receive at submit time. Directly passing the caller pid is unsafe for synchronous command handlers: when the caller times out, a late completion remains in that mailbox and can confuse later receives. This helper submits through a short-lived proxy process and replies through a process alias, so late replies are dropped after timeout instead of leaking into the caller.

This helper creates one short-lived BEAM process per wait. That cost is acceptable for synchronous cold reads, probabilistic reads, and cleanup operations, but it is not the final shape for a proven read-hot bottleneck. If benchmarking shows regression on hot async-NIF read workloads, replace per-read proxies with a tracked waiter/collector owned by the connection or command process, so correlation IDs are still isolated without spawning a process for every read.

Summary

Types

result()

@type result() :: {:ok, term()} | {:error, term()}

submit_fun()

@type submit_fun() :: (pid(), pos_integer() -> :ok | {:error, term()})

Functions

await(submit_fun, timeout_ms)

@spec await(submit_fun(), timeout()) :: result()