File tree 1 file changed +24
-0
lines changed
1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,8 @@ use std::{
8
8
ptr:: NonNull ,
9
9
} ;
10
10
11
+ #[ cfg( feature = "futures" ) ]
12
+ use crate :: runtime:: schedular:: SchedularPoll ;
11
13
#[ cfg( feature = "futures" ) ]
12
14
use crate :: AsyncContext ;
13
15
use crate :: {
@@ -386,6 +388,28 @@ impl<'js> Ctx<'js> {
386
388
res != 0
387
389
}
388
390
391
+ #[ cfg( feature = "futures" ) ]
392
+ pub fn poll ( & self , cx : & mut std:: task:: Context ) {
393
+ let spawner = unsafe { ( * self . get_opaque ( ) ) . spawner ( ) } ;
394
+ spawner. listen ( cx. waker ( ) . clone ( ) ) ;
395
+
396
+ let mut ptr = MaybeUninit :: < * mut qjs:: JSContext > :: uninit ( ) ;
397
+ let rt = unsafe { qjs:: JS_GetRuntime ( self . ctx . as_ptr ( ) ) } ;
398
+
399
+ loop {
400
+ // TODO: Handle error.
401
+ if unsafe { qjs:: JS_ExecutePendingJob ( rt, ptr. as_mut_ptr ( ) ) } != 0 {
402
+ continue ;
403
+ }
404
+
405
+ // TODO: Handle error.
406
+ match { spawner. poll ( cx) } {
407
+ SchedularPoll :: ShouldYield | SchedularPoll :: Empty | SchedularPoll :: Pending => break ,
408
+ SchedularPoll :: PendingProgress => { }
409
+ }
410
+ }
411
+ }
412
+
389
413
pub ( crate ) unsafe fn get_opaque ( & self ) -> * mut Opaque < ' js > {
390
414
let rt = qjs:: JS_GetRuntime ( self . ctx . as_ptr ( ) ) ;
391
415
qjs:: JS_GetRuntimeOpaque ( rt) . cast :: < Opaque > ( )
You can’t perform that action at this time.
0 commit comments