//! Stream subscription list with error handling and early termination.
//!
//! Run: `TICKSUPPLY_API_KEY=... cargo run --example streaming_subscriptions`

use futures::StreamExt;

#[tokio::main]
async fn main() -> ticksupply::Result<()> {
    let client = ticksupply::Client::new()?;
    let stream = client.subscriptions().list().limit(10).stream();
    tokio::pin!(stream);
    let mut count = 0;
    while let Some(item) = stream.next().await {
        match item {
            Ok(sub) => {
                count += 1;
                println!("{:3}: {} [{:?}]", count, sub.id, sub.status);
                if count >= 25 {
                    println!("stopping at 25");
                    break;
                }
            }
            Err(e) => {
                eprintln!("stream error: {e}");
                break;
            }
        }
    }
    Ok(())
}
