pub struct Query { /* private fields */ }Expand description
A registered live query. Subscribe to receive its raw change events.
Tear it down explicitly with Query::destroy. Dropping the handle is still a
no-op (the query keeps running and any callbacks keep firing), so an accidental
drop never silently stops delivery — teardown is always a deliberate call.
Implementations§
Source§impl Query
impl Query
Sourcepub fn id(&self) -> QueryId
pub fn id(&self) -> QueryId
The caller-supplied QueryId tag this query was registered under (echoed
verbatim; the engine never interprets it).
Sourcepub fn destroy(self)
pub fn destroy(self)
Tear this query down: stop delivering its events and reclaim its pipeline.
Removes its subscription registry entry (so no further Changed callbacks fire
and the hydration buffer is dropped), then disconnects it from the shared
sources and frees its operator/storage slots in the engine graph
([rindle::graph::Graph::destroy_pipeline]). The shared sources — and every other
query — are untouched. Consumes the handle; the freed slots are recycled by a
later crate::Db::query.
Like registration, this borrows the engine mutably, so it must not be called re-entrantly from inside a subscriber callback.
Sourcepub fn subscribe(&self, cb: impl FnMut(&Update) + 'static)
pub fn subscribe(&self, cb: impl FnMut(&Update) + 'static)
Register a callback and immediately call it with the cached Update::Hydrated.
This baseline is from registration or the latest shed recovery; ordinary writes
do not update it. Subscribe before later writes. A late consumer that needs the
current result should create a new query registration.
Later Changed callbacks run synchronously on the writer thread after commit.
A callback panic cannot roll back that SQL commit. Keep callbacks short, avoid
re-entering the Db, and forward events to a channel for other threads.
A shed recovery delivers a replacing Hydrated; see Update. Call
Query::destroy to stop the registration and all its callbacks.
A no-op (the callback is dropped without firing) in one edge: the query was torn
down because its post-shed re-hydration failed (see crate::CommitInfo::shed).