Expand description
Async-safe access to DejaDB.
Use AsyncDejaDB whenever the calling code is async. It is the supported
entry point for Tokio-based hosts, which is where most agent code lives.
§Why a separate handle
DejaDB is a blocking store: it owns a Tokio runtime internally and drives
each operation with Runtime::block_on. Tokio does not permit a runtime to be
started from within another runtime, so a DejaDB driven directly from async
code panics — in two distinct places:
- when an operation is called (
Cannot start a runtime from within a runtime); - when the handle is dropped, because dropping it drops the runtime it owns.
The second is the easier one to miss: code can look correct and still panic at teardown.
§What this handle does
- Every operation runs on Tokio’s blocking pool, where blocking is permitted.
- Concurrent callers queue asynchronously, so a burst of operations cannot exhaust the host’s blocking pool with threads that are only waiting their turn.
Dropmoves the store to a dedicated OS thread, so teardown never blocks an async worker.
Callers simply .await. The blocking DejaDB API is unchanged, and sync
callers pay nothing for this module.
§Example
use dejadb_store::AsyncDejaDB;
use dejadb_core::types::Fact;
let db = AsyncDejaDB::open("agent.db").await?;
db.add(Fact::new("john", "prefers", "dark mode")).await?;
let latest = db.latest("caller", "john", "prefers").await?;Structs§
- Async
DejaDB - A
DejaDBthat is safe to use from async code.