diff --git a/Cargo.lock b/Cargo.lock index e4aaec9..0cb3033 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -114,17 +114,6 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" -[[package]] -name = "async-channel" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf46fee83e5ccffc220104713af3292ff9bc7c64c7de289f66dae8e38d826833" -dependencies = [ - "concurrent-queue", - "event-listener", - "futures-core", -] - [[package]] name = "async-compression" version = "0.4.0" @@ -139,21 +128,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "async-lock" -version = "2.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa24f727524730b077666307f2734b4a1a1c57acb79193127dcc8914d5242dd7" -dependencies = [ - "event-listener", -] - -[[package]] -name = "async-task" -version = "4.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecc7ab41815b3c653ccd2978ec3255c81349336702dfdf62ee6f7069b12a3aae" - [[package]] name = "async-trait" version = "0.1.68" @@ -165,12 +139,6 @@ dependencies = [ "syn 2.0.18", ] -[[package]] -name = "atomic-waker" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1181e1e0d1fce796a03db1ae795d67167da795f9cf4a39c37589e85ef57f26d3" - [[package]] name = "atty" version = "0.2.14" @@ -252,21 +220,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "blocking" -version = "1.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77231a1c8f801696fc0123ec6150ce92cffb8e164a02afb9c8ddee0e9b65ad65" -dependencies = [ - "async-channel", - "async-lock", - "async-task", - "atomic-waker", - "fastrand", - "futures-lite", - "log", -] - [[package]] name = "brotli" version = "3.3.4" @@ -403,15 +356,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" -[[package]] -name = "concurrent-queue" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62ec6771ecfa0762d24683ee5a32ad78487a3d3afdc0fb8cae19d2c5deb50b7c" -dependencies = [ - "crossbeam-utils", -] - [[package]] name = "console" version = "0.15.7" @@ -659,12 +603,6 @@ dependencies = [ "libc", ] -[[package]] -name = "event-listener" -version = "2.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" - [[package]] name = "fastrand" version = "1.9.0" @@ -742,27 +680,6 @@ version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" -[[package]] -name = "futures-io" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" - -[[package]] -name = "futures-lite" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49a9d51ce47660b1e808d3c990b4709f2f415d928835a17dfd16991515c46bce" -dependencies = [ - "fastrand", - "futures-core", - "futures-io", - "memchr", - "parking", - "pin-project-lite", - "waker-fn", -] - [[package]] name = "futures-macro" version = "0.3.28" @@ -1174,7 +1091,6 @@ dependencies = [ "anyhow", "async-compression", "async-trait", - "blocking", "console", "dialoguer", "directories", @@ -1377,12 +1293,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "parking" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14f2252c834a40ed9bb5422029649578e63aa341ac401f74e719dd1afda8394e" - [[package]] name = "parking_lot" version = "0.12.1" @@ -2567,12 +2477,6 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" -[[package]] -name = "waker-fn" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" - [[package]] name = "want" version = "0.3.0" diff --git a/packages/lib/Cargo.toml b/packages/lib/Cargo.toml index 6d96df3..a810b49 100644 --- a/packages/lib/Cargo.toml +++ b/packages/lib/Cargo.toml @@ -35,7 +35,6 @@ toml.workspace = true tokio.workspace = true async-trait = "0.1" -blocking = "1.3" dialoguer = "0.10" dunce = "1.0" lz4_flex = "0.10" diff --git a/packages/lib/src/builtins/roblox.rs b/packages/lib/src/builtins/roblox.rs index 58f1ff7..b3d1b37 100644 --- a/packages/lib/src/builtins/roblox.rs +++ b/packages/lib/src/builtins/roblox.rs @@ -1,10 +1,10 @@ -use blocking::unblock; use mlua::prelude::*; use lune_roblox::{ document::{Document, DocumentError, DocumentFormat, DocumentKind}, instance::Instance, }; +use tokio::task; use crate::lua::table::TableBuilder; @@ -29,12 +29,12 @@ async fn deserialize_place<'lua>( contents: LuaString<'lua>, ) -> LuaResult> { let bytes = contents.as_bytes().to_vec(); - let fut = unblock(move || { + let fut = task::spawn_blocking(move || { let doc = Document::from_bytes(bytes, DocumentKind::Place)?; let data_model = doc.into_data_model_instance()?; Ok::<_, DocumentError>(data_model) }); - fut.await?.into_lua(lua) + fut.await.map_err(LuaError::external)??.into_lua(lua) } async fn deserialize_model<'lua>( @@ -42,12 +42,12 @@ async fn deserialize_model<'lua>( contents: LuaString<'lua>, ) -> LuaResult> { let bytes = contents.as_bytes().to_vec(); - let fut = unblock(move || { + let fut = task::spawn_blocking(move || { let doc = Document::from_bytes(bytes, DocumentKind::Model)?; let instance_array = doc.into_instance_array()?; Ok::<_, DocumentError>(instance_array) }); - fut.await?.into_lua(lua) + fut.await.map_err(LuaError::external)??.into_lua(lua) } async fn serialize_place<'lua>( @@ -55,7 +55,7 @@ async fn serialize_place<'lua>( (data_model, as_xml): (LuaUserDataRef<'lua, Instance>, Option), ) -> LuaResult> { let data_model = (*data_model).clone(); - let fut = unblock(move || { + let fut = task::spawn_blocking(move || { let doc = Document::from_data_model_instance(data_model)?; let bytes = doc.to_bytes_with_format(match as_xml { Some(true) => DocumentFormat::Xml, @@ -63,7 +63,7 @@ async fn serialize_place<'lua>( })?; Ok::<_, DocumentError>(bytes) }); - let bytes = fut.await?; + let bytes = fut.await.map_err(LuaError::external)??; lua.create_string(bytes) } @@ -72,7 +72,7 @@ async fn serialize_model<'lua>( (instances, as_xml): (Vec>, Option), ) -> LuaResult> { let instances = instances.iter().map(|i| (*i).clone()).collect(); - let fut = unblock(move || { + let fut = task::spawn_blocking(move || { let doc = Document::from_instance_array(instances)?; let bytes = doc.to_bytes_with_format(match as_xml { Some(true) => DocumentFormat::Xml, @@ -80,12 +80,12 @@ async fn serialize_model<'lua>( })?; Ok::<_, DocumentError>(bytes) }); - let bytes = fut.await?; + let bytes = fut.await.map_err(LuaError::external)??; lua.create_string(bytes) } async fn get_auth_cookie(_: &Lua, raw: Option) -> LuaResult> { - unblock(move || { + task::spawn_blocking(move || { if matches!(raw, Some(true)) { Ok(rbx_cookie::get_value()) } else { @@ -93,4 +93,5 @@ async fn get_auth_cookie(_: &Lua, raw: Option) -> LuaResult } }) .await + .map_err(LuaError::external)? } diff --git a/packages/lib/src/builtins/stdio.rs b/packages/lib/src/builtins/stdio.rs index 002fdb5..f497287 100644 --- a/packages/lib/src/builtins/stdio.rs +++ b/packages/lib/src/builtins/stdio.rs @@ -1,7 +1,9 @@ -use blocking::unblock; use dialoguer::{theme::ColorfulTheme, Confirm, Input, MultiSelect, Select}; use mlua::prelude::*; -use tokio::io::{self, AsyncWriteExt}; +use tokio::{ + io::{self, AsyncWriteExt}, + task, +}; use crate::lua::{ stdio::{ @@ -38,8 +40,10 @@ pub fn create(lua: &'static Lua) -> LuaResult { stderr.flush().await?; Ok(()) })? - .with_async_function("prompt", |_, options: PromptOptions| { - unblock(move || prompt(options)) + .with_async_function("prompt", |_, options: PromptOptions| async move { + task::spawn_blocking(move || prompt(options)) + .await + .map_err(LuaError::external)? })? .build_readonly() } diff --git a/packages/lib/src/lua/serde/compress_decompress.rs b/packages/lib/src/lua/serde/compress_decompress.rs index 2633f0f..528847b 100644 --- a/packages/lib/src/lua/serde/compress_decompress.rs +++ b/packages/lib/src/lua/serde/compress_decompress.rs @@ -1,7 +1,9 @@ -use blocking::unblock; use lz4_flex::{compress_prepend_size, decompress_size_prepended}; use mlua::prelude::*; -use tokio::io::{copy, BufReader}; +use tokio::{ + io::{copy, BufReader}, + task, +}; use async_compression::{ tokio::bufread::{ @@ -98,7 +100,9 @@ pub async fn compress<'lua>( ) -> LuaResult> { if let CompressDecompressFormat::LZ4 = format { let source = source.as_ref().to_vec(); - return Ok(unblock(move || compress_prepend_size(&source)).await); + return task::spawn_blocking(move || compress_prepend_size(&source)) + .await + .map_err(LuaError::external); } let mut bytes = Vec::new(); @@ -129,8 +133,9 @@ pub async fn decompress<'lua>( ) -> LuaResult> { if let CompressDecompressFormat::LZ4 = format { let source = source.as_ref().to_vec(); - return unblock(move || decompress_size_prepended(&source)) + return task::spawn_blocking(move || decompress_size_prepended(&source)) .await + .map_err(LuaError::external)? .map_err(LuaError::external); }