Struct barter_data::streams::builder::StreamBuilder
source · pub struct StreamBuilder<Kind>where
Kind: SubKind,{
pub channels: HashMap<ExchangeId, ExchangeChannel<MarketEvent<Kind::Event>>>,
pub futures: Vec<SubscribeFuture>,
}Expand description
Builder to configure and initialise a Streams<MarketEvent<SubKind::Event> instance
for a specific SubKind.
Fields§
§channels: HashMap<ExchangeId, ExchangeChannel<MarketEvent<Kind::Event>>>§futures: Vec<SubscribeFuture>Implementations§
source§impl<Kind> StreamBuilder<Kind>where
Kind: SubKind,
impl<Kind> StreamBuilder<Kind>where
Kind: SubKind,
sourcepub fn subscribe<SubIter, Sub, Exchange>(self, subscriptions: SubIter) -> Selfwhere
SubIter: IntoIterator<Item = Sub>,
Sub: Into<Subscription<Exchange, Kind>>,
Exchange: StreamSelector<Kind> + Ord + Send + Sync + 'static,
Kind: Ord + Send + Sync + 'static,
Kind::Event: Send,
Subscription<Exchange, Kind>: Identifier<Exchange::Channel> + Identifier<Exchange::Market>,
pub fn subscribe<SubIter, Sub, Exchange>(self, subscriptions: SubIter) -> Selfwhere
SubIter: IntoIterator<Item = Sub>,
Sub: Into<Subscription<Exchange, Kind>>,
Exchange: StreamSelector<Kind> + Ord + Send + Sync + 'static,
Kind: Ord + Send + Sync + 'static,
Kind::Event: Send,
Subscription<Exchange, Kind>: Identifier<Exchange::Channel> + Identifier<Exchange::Market>,
Add a collection of Subscriptions to the StreamBuilder that will be actioned on
a distinct WebSocket connection.
Note that Subscriptions are not actioned until the
init() method is invoked.
sourcepub async fn init(self) -> Result<Streams<MarketEvent<Kind::Event>>, DataError>
pub async fn init(self) -> Result<Streams<MarketEvent<Kind::Event>>, DataError>
Spawn a MarketEvent<SubKind::Event> consumer loop for each collection of
Subscriptions added to StreamBuilder via the
subscribe() method.
Each consumer loop distributes consumed MarketEvent<SubKind::Event>s to
the Streams HashMap returned by this method.