Skip to main content

block_on

Function block_on 

Source
pub fn block_on<F: Future>(future: F) -> F::Output
Available on crate feature async only.
Expand description

Drive a VisionKit async future to completion while pumping the Obj-C main run loop between polls.

Must be called from the main thread. VisionKit Swift Task { @MainActor in } thunks dispatch work to the main actor; without run-loop pumping the calling thread would deadlock when the main run loop is not free (e.g. inside pollster::block_on).

§Example

use visionkit::async_api::{AsyncImageAnalyzer, block_on};
use visionkit::{ImageAnalysisTypes, ImageAnalyzerConfiguration, ImageOrientation};

let cfg = ImageAnalyzerConfiguration::new(ImageAnalysisTypes::TEXT);
let analysis = block_on(async {
    AsyncImageAnalyzer::new()?
        .analyze_image_at_path("/path/to/image.png", ImageOrientation::Up, &cfg)?
        .await
});