Skip to main content

Module tokio

Module tokio 

Source
Expand description

AsyncReceiver on the Tokio runtime: the generic asynchronous::AsyncReceiver with Tokio, which run blocking work with tokio::task::spawn_blocking.

§Example

use grafton_ndi::{Ndi, ReceiverOptions, asynchronous::tokio::AsyncReceiver};

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

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

    // Capture without blocking the runtime
    match async_receiver.capture_video_with(std::time::Duration::from_millis(100), |frame| {
        (frame.width(), frame.height())
    }).await? {
        Some(size) => println!("Got dimensions: {size:?}"),
        None => println!("No frame available"),
    }

    Ok(())
}

See mixed_media_async.rs for a complete Tokio example.

Type Aliases§

AsyncFinder
Source discovery on the Tokio runtime, owning a finder or source cache.
AsyncReceiver
An AsyncReceiver on the Tokio runtime.
AsyncSourceCache
Cached discovery on the Tokio runtime.
AsyncSourceWatch
An owned discovery cursor on the Tokio runtime.