From 7da5350c79ce3cb8afa23c7790dd9c8956aa7fef Mon Sep 17 00:00:00 2001 From: sxyazi Date: Fri, 17 Jan 2025 01:16:51 +0800 Subject: [PATCH] .. --- yazi-plugin/src/utils/sync.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/yazi-plugin/src/utils/sync.rs b/yazi-plugin/src/utils/sync.rs index 1635d5bf..625352c3 100644 --- a/yazi-plugin/src/utils/sync.rs +++ b/yazi-plugin/src/utils/sync.rs @@ -43,17 +43,20 @@ impl Utils { pub(super) fn chan(lua: &Lua) -> mlua::Result { lua.create_function(|lua, (type_, buffer): (mlua::String, Option)| { match (&*type_.as_bytes(), buffer) { + (b"mpsc", Some(buffer)) if buffer < 1 => { + Err("Buffer size must be greater than 0".into_lua_err()) + } (b"mpsc", Some(buffer)) => { let (tx, rx) = tokio::sync::mpsc::channel::(buffer); - (MpscTx(tx), MpscRx(rx)).into_lua_multi(&lua) + (MpscTx(tx), MpscRx(rx)).into_lua_multi(lua) } (b"mpsc", None) => { let (tx, rx) = tokio::sync::mpsc::unbounded_channel::(); - (MpscUnboundedTx(tx), MpscUnboundedRx(rx)).into_lua_multi(&lua) + (MpscUnboundedTx(tx), MpscUnboundedRx(rx)).into_lua_multi(lua) } (b"oneshot", _) => { let (tx, rx) = tokio::sync::oneshot::channel::(); - (OneshotTx(Some(tx)), OneshotRx(Some(rx))).into_lua_multi(&lua) + (OneshotTx(Some(tx)), OneshotRx(Some(rx))).into_lua_multi(lua) } _ => Err("Channel type must be `mpsc` or `oneshot`".into_lua_err()), }