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>
impl<R: AsyncRuntime, D: SourceDiscovery> AsyncFinder<R, D>
Sourcepub fn new(discovery: D) -> Self
pub fn new(discovery: D) -> Self
Share an existing discovery owner without recreating its native finder.
Sourcepub fn finder(&self) -> &Finder
pub fn finder(&self) -> &Finder
The configured finder shared by every lookup and cursor of this adapter.
Sourcepub fn watch(&self) -> AsyncSourceWatch<R, D>
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.
Sourcepub async fn find_source(
&self,
timeout: Duration,
select: impl FnMut(&Source) -> bool + Send + 'static,
) -> Result<Option<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.
Sourcepub async fn find_source_by_name(
&self,
name: &str,
timeout: Duration,
) -> Result<Option<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.
Sourcepub async fn find_sources(&self, timeout: Duration) -> Result<Vec<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>
impl<R: AsyncRuntime> AsyncFinder<R, SourceCache>
Sourcepub fn cache(&self) -> &SourceCache
pub fn cache(&self) -> &SourceCache
The cache shared by this adapter, for invalidation and synchronous access.
Sourcepub async fn find_sources_by_host(
&self,
host: &str,
timeout: Duration,
) -> Result<Vec<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.