Skip to main content

AsyncRemoteSource

Trait AsyncRemoteSource 

Source
pub trait AsyncRemoteSource:
    Send
    + Sync
    + 'static {
    // Required methods
    fn fetch(
        &self,
    ) -> Pin<Box<dyn Future<Output = Result<Fetched, Error>> + Send + '_>>;
    fn describe(&self) -> String;

    // Provided methods
    fn watch_capability(&self) -> WatchCapability { ... }
    fn watch<'a>(
        &'a self,
        watching: &'a Watching,
        interval: Duration,
        on_change: &'a mut (dyn FnMut(Fetched) -> Result<(), Error> + Send),
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>> { ... }
}
Available on crate feature async only.
Expand description

A remote store that is read asynchronously.

The right trait for a client that is async to begin with — etcd speaks gRPC and NATS is a streaming protocol, so both are. Used through refresh_remote_async().await.

The lifetime-bound boxed future rather than async fn: this trait is object-safe on purpose, so a configuration type can hold one without being generic over it.

Required Methods§

Source

fn fetch( &self, ) -> Pin<Box<dyn Future<Output = Result<Fetched, Error>> + Send + '_>>

Reads the current document.

§Errors

As RemoteSource::fetch.

Source

fn describe(&self) -> String

How to name this source in an error or a report.

Provided Methods§

Source

fn watch_capability(&self) -> WatchCapability

How this store learns that its document changed.

As RemoteSource::watch_capability.

Source

fn watch<'a>( &'a self, watching: &'a Watching, interval: Duration, on_change: &'a mut (dyn FnMut(Fetched) -> Result<(), Error> + Send), ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>>

Watches until the future is dropped, calling on_change with every document that differs from the last one delivered.

As RemoteSource::watch, with two differences that matter. Cancellation is dropping the future, so a Watching is accepted but an async watch does not need one. And the resync a native store gets for free on the blocking side is the caller’s here: an async caller has a runtime, and racing a timer against this future is a line of its own code rather than a thread this crate would have to spawn.

The default polls only with the tokio feature on. This crate picks no runtime, and a poll needs a timer — so with the feature off the default refuses, naming the store and saying what to do about it. That is rarely the interesting case: a store is async because its protocol is, and a streaming protocol has a watch of its own to override this with.

§Errors

If on_change refuses a document, or if this build has no timer and the store did not override this.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§