impl Database {
pub fn query<'a>(&self, source: impl Into<Source<'a>>) -> Result<Query>; // stored path or inline Document
}
impl Query {
pub fn subscribe(&self, parameters: Option<&Document>, options: &RunOptions) -> Result<Subscription>;
}
impl Subscription {
pub fn next(&self, max_wait: Duration) -> Result<Option<Event>>; // Ok(None) = timed out
pub fn events(&self) -> Events<'_>; // Iterator<Item = Result<Event>>, waits with no limit
pub fn cancel(&self);
pub fn close(&self);
}
pub struct Event {
pub sequence: i64,
pub superseded: i64,
pub transaction: i64,
pub result: Document,
}impl Query {
pub async fn subscribe(&self, parameters: Option<&Document>, options: &RunOptions) -> Result<Subscription>;
}
impl Subscription {
pub async fn next(&self, max_wait: Duration) -> Result<Option<Event>>;
pub async fn events(&self) -> Events<'_>;
pub async fn cancel(&self) -> Result<()>;
pub async fn close(&self) -> Result<()>;
}nextstill takesmax_wait. In async code timeouts usually come from the runtime (timeout,select!).Ok(None)means "timed out", not "ended".cancelisasyncand returnsResult. Its natural callers (a Ctrl-C handler, aDrop) can't.await. The syncfn cancel(&self)is the better shape.events()isasync fnreturningEvents<'_>: is that aStream, or does it have its ownnext().await?&selfeverywhere allows concurrentnextcallers. The C ABI supports that, but a single consumer (&mut self) plus a cloneable canceller is simpler.
Proposal: https://gist.github.com/cablehead/7c0078019081652047aec648497bf1d0