@@ -7,14 +7,16 @@ use crate::zend::Function;
7
7
use std:: cell:: RefCell ;
8
8
use std:: fs:: File ;
9
9
use std:: future:: Future ;
10
- use std:: io;
10
+ use std:: io:: { self , Write } ;
11
11
use std:: os:: fd:: { RawFd , FromRawFd } ;
12
12
use std:: sync:: mpsc:: { Sender , Receiver , channel} ;
13
13
use std:: io:: Read ;
14
14
use lazy_static:: lazy_static;
15
15
use tokio:: runtime:: Runtime ;
16
16
use std:: os:: fd:: AsRawFd ;
17
17
18
+ use super :: borrow_unchecked;
19
+
18
20
lazy_static ! {
19
21
pub static ref RUNTIME : Runtime = Runtime :: new( ) . expect( "Could not allocate runtime" ) ;
20
22
}
@@ -60,23 +62,25 @@ impl EventLoop {
60
62
}
61
63
62
64
pub fn suspend_on < T : Send + ' static , F : Future < Output = T > + Send + ' static > ( future : F ) -> T {
63
- let future = EVENTLOOP . with_borrow_mut ( move |c| {
65
+ let ( future, get_current_suspension ) = EVENTLOOP . with_borrow_mut ( move |c| {
64
66
let c = c. as_mut ( ) . unwrap ( ) ;
65
67
let idx = c. fibers . len ( ) as u64 ;
66
68
c. fibers . insert_at_index ( idx, call_user_func ! ( c. get_current_suspension) . unwrap ( ) ) . unwrap ( ) ;
67
69
68
70
let sender = c. sender . clone ( ) ;
69
71
let mut notifier = c. notify_sender . try_clone ( ) . unwrap ( ) ;
70
72
71
- RUNTIME . spawn ( async move {
73
+ ( RUNTIME . spawn ( async move {
72
74
let res = future. await ;
73
75
sender. send ( idx) . unwrap ( ) ;
74
- :: std :: io :: Write :: write_all ( & mut notifier , & [ 0 ] ) . unwrap ( ) ;
76
+ notifier . write_all ( & [ 0 ] ) . unwrap ( ) ;
75
77
res
78
+ } ) , unsafe {
79
+ borrow_unchecked ( & c. get_current_suspension )
76
80
} )
77
81
} ) ;
78
82
79
- call_user_func ! ( Function :: from_method ( " \\ Revolt \\ EventLoop" , "getSuspension" ) ) . unwrap ( ) . try_call_method ( "suspend" , vec ! [ ] ) . unwrap ( ) ;
83
+ call_user_func ! ( get_current_suspension ) . unwrap ( ) . try_call_method ( "suspend" , vec ! [ ] ) . unwrap ( ) ;
80
84
81
85
return RUNTIME . block_on ( future) . unwrap ( ) ;
82
86
}
0 commit comments