Skip to main content

Module async_std

Module async_std 

Source
Expand description

async-std runtime integration.

Provides AsyncReceiver wrapper that uses async_std::task::spawn_blocking to run NDI operations without blocking the async-std runtime.

§Example

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

#[async_std::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 async-std runtime.