Struct SendPeer
pub struct SendPeer<P> { /* private fields */ }Expand description
A StoreSyncPeer or RemoteSyncPeer of the
SendSyncPeer flavour.
It answers exactly as the peer it wraps: each method delegates, and the
Error and Resume are the
wrapped peer’s. What it adds is the promise: its futures are Send, so a
function generic over SendSyncPeer can hold them across a
tokio::spawn. Through trait_variant’s blanket impl it is a bare
SyncPeer too.
It implements the flavour for two peers and their Send halves:
SendPeer<StoreSyncPeer<S, I, A>>, forS:SendWriteGroupStore+ Sync,I:SendIngestStore+ Syncand a merge ruleA:SendAdjudicate+ Sync, whichAccept, the default, is;SendPeer<RemoteSyncPeer<X>>, forX:SendExchange+ Sync.
Sync because a pull or a push holds &self across its awaits, and a
borrow is Send only when what it borrows is Sync.
It is not a wrapper for any SyncPeer. A bare peer’s futures promise
nothing about Send, and stable Rust has no way to ask “whose pull
future is Send” of a generic P, so the impl is written per peer, where
the halves’ own flavours supply the promise.
§Examples
use happenstance_sync::{SendPeer, SendSyncPeer, StoreSyncPeer};
// Generic code that may spawn knows the peer by the `Send` flavour only.
fn spawnable<P: SendSyncPeer + Sync>(_peer: &P) {}
let hub = Shared(std::sync::Arc::new(happenstance_sync::MemoryIngestStore::new()));
let peer = SendPeer::new(StoreSyncPeer::new(hub.clone(), hub));
spawnable(&peer);Implementations§
Trait Implementations§
§impl<S, I, A> SendSyncPeer for SendPeer<StoreSyncPeer<S, I, A>>
impl<S, I, A> SendSyncPeer for SendPeer<StoreSyncPeer<S, I, A>>
§async fn pull(
&self,
from: Option<&StoreResume>,
) -> Result<Pulled<StoreResume>, Self::Error>
async fn pull( &self, from: Option<&StoreResume>, ) -> Result<Pulled<StoreResume>, Self::Error>
§type Error = <StoreSyncPeer<S, I, A> as SyncPeer>::Error
type Error = <StoreSyncPeer<S, I, A> as SyncPeer>::Error
§type Resume = StoreResume
type Resume = StoreResume
§fn limits(&self) -> PeerLimits
fn limits(&self) -> PeerLimits
§impl<X> SendSyncPeer for SendPeer<RemoteSyncPeer<X>>where
X: SendExchange + Sync,
impl<X> SendSyncPeer for SendPeer<RemoteSyncPeer<X>>where
X: SendExchange + Sync,
§async fn pull(
&self,
from: Option<&ResumeToken>,
) -> Result<Pulled<ResumeToken>, Self::Error>
async fn pull( &self, from: Option<&ResumeToken>, ) -> Result<Pulled<ResumeToken>, Self::Error>
§async fn push(&self, batch: &PushBatch) -> Result<Ack, Self::Error>
async fn push(&self, batch: &PushBatch) -> Result<Ack, Self::Error>
RemoteSyncPeer’s push: one Route::Push
exchange, or none when the declared limits refuse the batch.
§Errors
As RemoteSyncPeer’s push.