Skip to main content

AsyncFinder

Struct AsyncFinder 

Source
pub struct AsyncFinder<R: AsyncRuntime, D: SourceDiscovery = Finder> { /* private fields */ }
Expand description

Async discovery through one owned Finder or SourceCache.

R selects Tokio or Smol, when its feature is enabled. Clones share the owner through an Arc; Self::finder lends its configured finder for synchronous controls. Constructing this adapter does not recreate a finder or change its groups, IP hints, local-source policy or runtime.

Wait budgets start on first poll and include blocking-pool queue delay and snapshot-lock contention. Dropping a future skips queued work and stops a started wait within its next native attempt, at most 100 ms. A snapshot copy or predicate already running finishes, and can outlast the budget. Native waits and condvar waits are sliced only for these stoppable calls; synchronous discovery keeps its full-budget wait, avoiding the extra native calls. On idle Linux x86-64 finders with Standard 6.3.2/6.4.0.2, slicing measured about 0.1–0.2 ms of calling-thread CPU per second of waiting; other workloads and platforms can differ. Predicates run outside SDK locks; their panics resume on the awaiting task.

use grafton_ndi::{asynchronous::tokio::AsyncFinder, Finder, FinderOptions, Ndi};
use std::time::Duration;
let ndi = Ndi::new()?;
let finder = AsyncFinder::new(Finder::new(&ndi, &FinderOptions::new())?);
let source = finder.find_source_by_name("STUDIO (Program)", Duration::from_secs(5)).await?;
println!("{source:?}");

Implementations§

Source§

impl<R: AsyncRuntime, D: SourceDiscovery> AsyncFinder<R, D>

Source

pub fn new(discovery: D) -> Self

Share an existing discovery owner without recreating its native finder.

Source

pub fn finder(&self) -> &Finder

The configured finder shared by every lookup and cursor of this adapter.

Source

pub fn watch(&self) -> AsyncSourceWatch<R, D>

Create one owned cursor that can move into a spawned async task.

Each consumer needs its own cursor. This records the current generation and clones an Arc, without allocating or calling the SDK.

Source

pub async fn find_source( &self, timeout: Duration, select: impl FnMut(&Source) -> bool + Send + 'static, ) -> Result<Option<Source>>

Find the first source accepted by select, as Finder::find_source.

The predicate is owned by the blocking worker and must be Send + 'static. After its snapshot, the worker checks for cancellation before each predicate call. A call that has passed its check may finish.

§Errors

Invalid timeouts are refused before submitting work. Snapshot and resource errors propagate; crate::Error::SpawnFailed reports dispatch failure.

Source

pub async fn find_source_by_name( &self, name: &str, timeout: Duration, ) -> Result<Option<Source>>

Find an exact complete name, as Finder::find_source_by_name.

§Errors

The errors and argument validation of Finder::find_source_by_name, before submitting work, plus dispatch failure.

Source

pub async fn find_sources(&self, timeout: Duration) -> Result<Vec<Source>>

Observe the full discovery window, as Finder::find_sources.

§Errors

Invalid timeouts are refused before submitting work. Bounded snapshot and accumulated-result errors propagate, as does dispatch failure.

Source§

impl<R: AsyncRuntime> AsyncFinder<R, SourceCache>

Source

pub fn cache(&self) -> &SourceCache

The cache shared by this adapter, for invalidation and synchronous access.

Source

pub async fn find_sources_by_host( &self, host: &str, timeout: Duration, ) -> Result<Vec<Source>>

Return cached feeds or observe a host’s full discovery window.

As SourceCache::find_sources_by_host, including best-effort publication. A cancelled miss does not publish an incomplete discovery window. Cache hits return owned descriptor copies on the awaiting task without the blocking pool. Invalidation after a miss is observed suppresses its publication even while its worker is queued. The lookup can still return its discovered feeds.

§Errors

The errors and argument validation of SourceCache::find_sources_by_host, before submitting work. Dispatch errors also propagate.

Trait Implementations§

Source§

impl<R: AsyncRuntime, D: SourceDiscovery> Clone for AsyncFinder<R, D>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<R: AsyncRuntime, D: SourceDiscovery> Debug for AsyncFinder<R, D>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<R, D> Freeze for AsyncFinder<R, D>

§

impl<R, D> RefUnwindSafe for AsyncFinder<R, D>

§

impl<R, D> Send for AsyncFinder<R, D>

§

impl<R, D> Sync for AsyncFinder<R, D>

§

impl<R, D> Unpin for AsyncFinder<R, D>
where R: Unpin,

§

impl<R, D> UnsafeUnpin for AsyncFinder<R, D>

§

impl<R, D> UnwindSafe for AsyncFinder<R, D>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.