Skip to content

Commit cb93865

Browse files
authored
Merge pull request #242 from compio-rs/dependabot/cargo/block2-0.5.0
build(deps): update block2 requirement from 0.4.0 to 0.5.0
2 parents 14e8d63 + 1461d96 commit cb93865

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

compio-runtime/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ windows-sys = { workspace = true, features = ["Win32_UI_WindowsAndMessaging"] }
5757

5858
[target.'cfg(target_os = "macos")'.dev-dependencies]
5959
core-foundation = "0.9.4"
60-
block2 = "0.4.0"
60+
block2 = "0.5.0"
6161

6262
[target.'cfg(not(any(windows, target_os = "macos")))'.dev-dependencies]
6363
glib = "0.19"

compio-runtime/tests/custom_loop.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
#[cfg(target_os = "macos")]
22
#[test]
33
fn cf_run_loop() {
4-
use std::{future::Future, os::raw::c_void, time::Duration};
4+
use std::{
5+
future::Future,
6+
os::raw::c_void,
7+
sync::{Arc, Mutex},
8+
time::Duration,
9+
};
510

6-
use block2::{Block, ConcreteBlock};
11+
use block2::{Block, StackBlock};
712
use compio_driver::AsRawFd;
813
use compio_runtime::{event::Event, Runtime};
914
use core_foundation::{
@@ -70,11 +75,12 @@ fn cf_run_loop() {
7075
compio_runtime::time::sleep(Duration::from_secs(1)).await;
7176

7277
let event = Event::new();
73-
let block = ConcreteBlock::new(|| {
74-
event.handle().notify();
78+
let handle = Arc::new(Mutex::new(Some(event.handle())));
79+
let block = StackBlock::new(move || {
80+
handle.lock().unwrap().take().unwrap().notify();
7581
});
7682
extern "C" {
77-
fn CFRunLoopPerformBlock(rl: CFRunLoopRef, mode: CFStringRef, block: &Block<(), ()>);
83+
fn CFRunLoopPerformBlock(rl: CFRunLoopRef, mode: CFStringRef, block: &Block<dyn Fn()>);
7884
}
7985
let run_loop = CFRunLoop::get_current();
8086
unsafe {

0 commit comments

Comments
 (0)