SubscriptionStream
A type alias for the pinned, boxed Stream returned by every subscription call.
Definition
pub type SubscriptionStream<T> =
Pin<Box<dyn Stream<Item = Result<Response<T>, WsError>> + Send>>;Response<T> is graphql_client::Response<T>, with data: Option<T> and errors: Option<Vec<...>>. WsError is the SDK's WebSocket error enum.
Construction
SubscriptionStream<T> is produced by:
WsClient::subscribe— dedicated connection.Session::subscribe— multiplexed.SubscriptionVariables::subscribe— sugar overWsClient::subscribe.
There is no public constructor outside the SDK.
Example
use {
anyhow::Result,
dango_sdk::{SubscribeBlock, WsClient, WsError, subscribe_block},
futures::StreamExt,
};
#[tokio::main]
async fn main() -> Result<()> {
let ws = WsClient::new("wss://api-mainnet.dango.zone/graphql")?;
let mut stream = ws
.subscribe::<SubscribeBlock>(subscribe_block::Variables {})
.await?;
while let Some(item) = stream.next().await {
match item {
Ok(resp) => println!("data: {:?}", resp.data),
Err(WsError::Closed(reason)) => {
eprintln!("closed: {reason}");
break;
}
Err(err) => eprintln!("ws: {err}"),
}
}
Ok(())
}Notes
Sendbut notSync. Move the stream into a single task; do not share by reference across threads.- Already pinned and boxed — no need for an outer
Box::pinwhen consuming withStreamExt::next. - Dropping the stream sends a
Completeto the server and frees the slot in the 30-per-connection cap. - On
WsError::ClosedorWsError::Transport, the stream terminates.WsError::Subscriptionterminates this stream but the parentSessionkeeps running for other subscriptions.