char/avril
(wip) why'd you have to go and make things so complicaaaaated?
git clone https://git.t4t.associates/char/avril
b2fc926
main
1use std:: cell:: RefCell ; 2use std:: convert:: Infallible ; 3use std:: io; 4use std:: rc:: Rc ; 5use std:: sync:: Arc ; 6 7use avril_caps:: Capabilities ; 8use avril_core:: serde_v8:: JsBuffer ; 9use avril_core::{ Extension , Op }; 10use avril_host:: environment:: Environment ; 11use tokio:: runtime:: Handle ; 12 13use avril_ext_file:: Files ; 14use avril_host:: io:: response; 15 16pub struct Tree ; 17# [ allow ( dead_code )] 18impl Tree { 19pub fn global () ->Arc < Self > { 20Arc :: new ( Self ) 21} 22pub ( crate ) fn stop_live_processes ( & self ) {} 23pub fn force_live_processes ( & self ) {} 24pub fn stop_sync_processes ( & self ) {} 25pub fn claim_term ( 26& self , 27runtime : & Handle , 28owner : Arc < dyn Fn () +Send +Sync >, 29) -> io:: Result <()> { 30# [ cfg ( unix )] 31{ 32let _enter = runtime. enter (); 33let mut termination = 34 tokio:: signal:: unix:: signal ( tokio:: signal:: unix:: SignalKind :: terminate ()) ?; 35 runtime. spawn ( async move { 36while termination. recv (). await . is_some () { 37owner (); 38} 39}); 40} 41# [ cfg ( not ( unix ))] 42let _ =( runtime, owner); 43Ok (()) 44} 45} 46 47pub fn init ( 48runtime : Handle , 49_caps : Arc < Capabilities >, 50_environment : Rc < RefCell < Environment >>, 51_files : Arc < Files >, 52_owner : tokio_util:: sync:: CancellationToken , 53worker : bool , 54_signal : super :: SignalMode , 55) ->Extension { 56let unavailable = ||{ 57response ( Err ::<(), _ >( io:: Error :: new ( 58 io:: ErrorKind :: Unsupported , 59"Subprocess execution is not supported on this platform" , 60))) 61}; 62let mut ops =vec! [ 63Op :: new ( "op_process_spawn" , move |_options : serde_json:: Value |{ 64Ok ::< _ , Infallible >( unavailable ()) 65}), 66Op :: new ( 67"op_process_run_sync" , 68move |_options : ( serde_json:: Value , Option < JsBuffer >) |{ 69Ok ::< _ , Infallible >( unavailable ()) 70}, 71), 72Op :: new ( "op_process_release" , |_id : u64 |Ok ::< _ , Infallible >(())), 73]; 74for namein [ 75"op_process_cancel_read" , 76"op_process_ref" , 77"op_process_kill" , 78"op_process_stop" , 79"op_process_resize" , 80] { 81 ops. push ( Op :: new ( name, move |_args : serde_json:: Value |{ 82Ok ::< _ , Infallible >( unavailable ()) 83})); 84} 85for namein [ 86"op_process_read" , 87"op_process_write" , 88"op_process_end" , 89"op_process_wait" , 90] { 91 ops. push ( Op :: asynchronous_unreferenced ( 92 name, 93move |_args : serde_json:: Value |async move { Ok ::< _ , Infallible >( unavailable ()) }, 94)); 95} 96 ops. push ( Op :: asynchronous ( 97"op_process_keepalive" , 98move |_args : serde_json:: Value |async move { Ok ::< _ , Infallible >( unavailable ()) }, 99)); 100// Signal listeners report NotSupported through the shared ops, like the 101// file operations map Unsupported. 102 ops. extend ( super :: signals:: ops ( & super :: signals:: State :: create ( 103 runtime, worker, 104))); 105Extension { 106name : "ext:process" , 107dependencies : & [ "ext:encoding" , "ext:file" , "ext:web" , "ext:webstreams" ], 108 ops, 109modules : & [ 110( 111"ext:process/main.js" , 112include_str! ( concat! ( env! ( "OUT_DIR" ), "/process.js" )), 113), 114( 115"ext:process/signals.js" , 116include_str! ( concat! ( env! ( "OUT_DIR" ), "/signals.js" )), 117), 118], 119entry_point : None , 120} 121}