@@ -6,32 +6,31 @@ use yazi_proxy::{AppProxy, options::{PluginCallback, PluginOpt}};
6
6
use yazi_shared:: event:: Data ;
7
7
8
8
use 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 } ;
10
10
11
11
impl Utils {
12
12
pub ( super ) fn sync ( lua : & Lua , isolate : bool ) -> mlua:: Result < Function > {
13
13
if isolate {
14
14
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 {
16
16
return Err ( "`ya.sync()` must be called in a plugin" ) . into_lua_err ( ) ;
17
17
} ;
18
18
19
19
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 ?)
25
24
} )
26
25
} )
27
26
} else {
28
27
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" ) ?;
30
29
if !rt. put_block ( f. clone ( ) ) {
31
30
return Err ( "`ya.sync()` must be called in a plugin" ) . into_lua_err ( ) ;
32
31
}
33
32
34
- let cur = rt. current ( ) . unwrap ( ) . to_owned ( ) ;
33
+ let cur = rt. current_owned ( ) . unwrap ( ) ;
35
34
lua. create_function ( move |lua, mut args : MultiValue | {
36
35
args. push_front ( Value :: Table ( LOADER . try_load ( lua, & cur) ?) ) ;
37
36
f. call :: < MultiValue > ( args)
@@ -78,14 +77,14 @@ impl Utils {
78
77
lua. create_async_function ( |_lua, _futs : MultiValue | async move { Ok ( ( ) ) } )
79
78
}
80
79
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 > > {
82
81
let args = Sendable :: values_to_list ( args) ?;
83
82
let ( tx, rx) = oneshot:: channel :: < Vec < Data > > ( ) ;
84
83
85
84
let callback: PluginCallback = {
86
- let id = id. to_owned ( ) ;
85
+ let id_ = id. clone ( ) ;
87
86
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 {
89
88
return Err ( "sync block not found" . into_lua_err ( ) ) ;
90
89
} ;
91
90
@@ -99,7 +98,7 @@ impl Utils {
99
98
} )
100
99
} ;
101
100
102
- AppProxy :: plugin ( PluginOpt :: new_callback ( id, callback) ) ;
101
+ AppProxy :: plugin ( PluginOpt :: new_callback ( id. clone ( ) , callback) ) ;
103
102
104
103
rx. await
105
104
. map_err ( |_| format ! ( "Failed to execute sync block-{calls} in `{id}` plugin" ) . into_lua_err ( ) )
0 commit comments