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 on the current thread.

On the main thread it pumps the Obj-C main run loop until the future is woken, because VisionKit completes its work through the main queue (and the overlay-subject queries run on the main actor). On any other thread it parks until woken; the futures then complete only while the main thread is running its run loop, as it does in an AppKit app.

§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
});