@@ -6,32 +6,31 @@ use yazi_proxy::{AppProxy, options::{PluginCallback, PluginOpt}};
66use yazi_shared:: event:: Data ;
77
88use super :: Utils ;
9- use crate :: { bindings:: { MpscRx , MpscTx , MpscUnboundedRx , MpscUnboundedTx , OneshotRx , OneshotTx } , loader:: LOADER , runtime:: RtRef } ;
9+ use crate :: { RtRefMut , bindings:: { MpscRx , MpscTx , MpscUnboundedRx , MpscUnboundedTx , OneshotRx , OneshotTx } , loader:: LOADER , runtime:: RtRef } ;
1010
1111impl Utils {
1212 pub ( super ) fn sync ( lua : & Lua , isolate : bool ) -> mlua:: Result < Function > {
1313 if isolate {
1414 lua. create_function ( |lua, ( ) | {
15- let Some ( block) = lua. named_registry_value :: < RtRef > ( "rt" ) ?. next_block ( ) else {
15+ let Some ( block) = lua. named_registry_value :: < RtRefMut > ( "rt" ) ?. next_block ( ) else {
1616 return Err ( "`ya.sync()` must be called in a plugin" ) . into_lua_err ( ) ;
1717 } ;
1818
1919 lua. create_async_function ( move |lua, args : MultiValue | async move {
20- if let Some ( cur) = lua. named_registry_value :: < RtRef > ( "rt" ) ?. current ( ) {
21- Sendable :: list_to_values ( & lua, Self :: retrieve ( cur, block, args) . await ?)
22- } else {
23- Err ( "block spawned by `ya.sync()` must be called in a plugin" ) . into_lua_err ( )
24- }
20+ let Some ( cur) = lua. named_registry_value :: < RtRef > ( "rt" ) ?. current_owned ( ) else {
21+ return Err ( "block spawned by `ya.sync()` must be called in a plugin" ) . into_lua_err ( ) ;
22+ } ;
23+ Sendable :: list_to_values ( & lua, Self :: retrieve ( cur, block, args) . await ?)
2524 } )
2625 } )
2726 } else {
2827 lua. create_function ( |lua, f : Function | {
29- let mut rt = lua. named_registry_value :: < RtRef > ( "rt" ) ?;
28+ let mut rt = lua. named_registry_value :: < RtRefMut > ( "rt" ) ?;
3029 if !rt. put_block ( f. clone ( ) ) {
3130 return Err ( "`ya.sync()` must be called in a plugin" ) . into_lua_err ( ) ;
3231 }
3332
34- let cur = rt. current ( ) . unwrap ( ) . to_owned ( ) ;
33+ let cur = rt. current_owned ( ) . unwrap ( ) ;
3534 lua. create_function ( move |lua, mut args : MultiValue | {
3635 args. push_front ( Value :: Table ( LOADER . try_load ( lua, & cur) ?) ) ;
3736 f. call :: < MultiValue > ( args)
@@ -78,14 +77,14 @@ impl Utils {
7877 lua. create_async_function ( |_lua, _futs : MultiValue | async move { Ok ( ( ) ) } )
7978 }
8079
81- async fn retrieve ( id : & str , calls : usize , args : MultiValue ) -> mlua:: Result < Vec < Data > > {
80+ async fn retrieve ( id : String , calls : usize , args : MultiValue ) -> mlua:: Result < Vec < Data > > {
8281 let args = Sendable :: values_to_list ( args) ?;
8382 let ( tx, rx) = oneshot:: channel :: < Vec < Data > > ( ) ;
8483
8584 let callback: PluginCallback = {
86- let id = id. to_owned ( ) ;
85+ let id_ = id. clone ( ) ;
8786 Box :: new ( move |lua, plugin| {
88- let Some ( block) = lua. named_registry_value :: < RtRef > ( "rt" ) ?. get_block ( & id , calls) else {
87+ let Some ( block) = lua. named_registry_value :: < RtRef > ( "rt" ) ?. get_block ( & id_ , calls) else {
8988 return Err ( "sync block not found" . into_lua_err ( ) ) ;
9089 } ;
9190
@@ -99,7 +98,7 @@ impl Utils {
9998 } )
10099 } ;
101100
102- AppProxy :: plugin ( PluginOpt :: new_callback ( id, callback) ) ;
101+ AppProxy :: plugin ( PluginOpt :: new_callback ( id. clone ( ) , callback) ) ;
103102
104103 rx. await
105104 . map_err ( |_| format ! ( "Failed to execute sync block-{calls} in `{id}` plugin" ) . into_lua_err ( ) )
0 commit comments