Skip to main content

Module tokio

Module tokio 

Source
Expand description

Tokio async runtime integration.

Provides AsyncReceiver wrapper that uses tokio::task::spawn_blocking to run NDI operations without blocking the Tokio runtime.

§Example

use grafton_ndi::{NDI, ReceiverOptionsBuilder, tokio::AsyncReceiver};

#[tokio::main]
async fn main() -> Result<(), grafton_ndi::Error> {
    let ndi = NDI::new()?;
    // ... obtain source ...

    let options = ReceiverOptionsBuilder::snapshot_preset(source).build();
    let receiver = grafton_ndi::Receiver::new(&ndi, &options)?;
    let async_receiver = AsyncReceiver::new(receiver);

    // Non-blocking async capture
    match async_receiver.video().try_capture(std::time::Duration::from_millis(100)).await? {
        Some(frame) => println!("Got frame: {}x{}", frame.width(), frame.height()),
        None => println!("No frame available"),
    }

    Ok(())
}

Type Aliases§

AsyncReceiver
Async receiver wrapper for Tokio runtime.