Skip to content

Commit 1461d96

Browse files
committed
fix: use StackBlock correctly
1 parent 8d26afb commit 1461d96

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

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)