-
Is there a way to use screen capture kit in sync code? |
Beta Was this translation helpful? Give feedback.
Answered by
Kree0
Nov 17, 2024
Replies: 2 comments 1 reply
-
Yes. You can use blocks or closures. Usually, they end with For instance: pub async fn start() -> -> Result<(), arc::R<ns::Error>>;
pub fn start_with_ch_block(&self, ch: Option<&mut blocks::ErrCompletionHandler>);
pub fn start_with_ch(&self, ch: impl FnMut(Option<&ns::Error>) + 'static) { |
Beta Was this translation helpful? Give feedback.
1 reply
-
without fn main() {
let sema = dispatch::Semaphore::new(0);
let mut sema_guard = sema.guard();
let content = Arc::new(Mutex::new(None));
sc::ShareableContent::current_with_ch({
let content = content.clone();
move |c, e| {
if let Some(c) = c {
*content.lock().unwrap() = Some(c.retained());
} else {
eprintln!("error: {e:?}");
}
sema_guard.consume();
}
});
sema.wait_forever();
let Some(content) = content.lock().unwrap().take() else {
return;
};
println!("{content:?}");
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, I use
std::sync::mpsc::channel()
, it works well for me: