mirror of
https://github.com/lune-org/lune.git
synced 2025-04-11 22:10:53 +01:00
Use scheduler blocking threadpool instead of tokio
This commit is contained in:
parent
3e80e7934a
commit
ede4682b1e
5 changed files with 21 additions and 27 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1350,6 +1350,7 @@ dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"async-compression",
|
"async-compression",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
|
"blocking",
|
||||||
"chrono",
|
"chrono",
|
||||||
"chrono_lc",
|
"chrono_lc",
|
||||||
"clap",
|
"clap",
|
||||||
|
|
|
@ -79,6 +79,7 @@ urlencoding = "2.1"
|
||||||
|
|
||||||
### RUNTIME
|
### RUNTIME
|
||||||
|
|
||||||
|
blocking = "1.5"
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
||||||
tokio = { version = "1.24", features = ["full", "tracing"] }
|
tokio = { version = "1.24", features = ["full", "tracing"] }
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use mlua::prelude::*;
|
use mlua::prelude::*;
|
||||||
|
use mlua_luau_scheduler::LuaSpawnExt;
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -11,8 +12,6 @@ use crate::{
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
use tokio::task;
|
|
||||||
|
|
||||||
static REFLECTION_DATABASE: OnceCell<ReflectionDatabase> = OnceCell::new();
|
static REFLECTION_DATABASE: OnceCell<ReflectionDatabase> = OnceCell::new();
|
||||||
|
|
||||||
pub fn create(lua: &Lua) -> LuaResult<LuaTable> {
|
pub fn create(lua: &Lua) -> LuaResult<LuaTable> {
|
||||||
|
@ -41,12 +40,12 @@ async fn deserialize_place<'lua>(
|
||||||
contents: LuaString<'lua>,
|
contents: LuaString<'lua>,
|
||||||
) -> LuaResult<LuaValue<'lua>> {
|
) -> LuaResult<LuaValue<'lua>> {
|
||||||
let bytes = contents.as_bytes().to_vec();
|
let bytes = contents.as_bytes().to_vec();
|
||||||
let fut = task::spawn_blocking(move || {
|
let fut = lua.spawn_blocking(move || {
|
||||||
let doc = Document::from_bytes(bytes, DocumentKind::Place)?;
|
let doc = Document::from_bytes(bytes, DocumentKind::Place)?;
|
||||||
let data_model = doc.into_data_model_instance()?;
|
let data_model = doc.into_data_model_instance()?;
|
||||||
Ok::<_, DocumentError>(data_model)
|
Ok::<_, DocumentError>(data_model)
|
||||||
});
|
});
|
||||||
fut.await.into_lua_err()??.into_lua(lua)
|
fut.await.into_lua_err()?.into_lua(lua)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn deserialize_model<'lua>(
|
async fn deserialize_model<'lua>(
|
||||||
|
@ -54,12 +53,12 @@ async fn deserialize_model<'lua>(
|
||||||
contents: LuaString<'lua>,
|
contents: LuaString<'lua>,
|
||||||
) -> LuaResult<LuaValue<'lua>> {
|
) -> LuaResult<LuaValue<'lua>> {
|
||||||
let bytes = contents.as_bytes().to_vec();
|
let bytes = contents.as_bytes().to_vec();
|
||||||
let fut = task::spawn_blocking(move || {
|
let fut = lua.spawn_blocking(move || {
|
||||||
let doc = Document::from_bytes(bytes, DocumentKind::Model)?;
|
let doc = Document::from_bytes(bytes, DocumentKind::Model)?;
|
||||||
let instance_array = doc.into_instance_array()?;
|
let instance_array = doc.into_instance_array()?;
|
||||||
Ok::<_, DocumentError>(instance_array)
|
Ok::<_, DocumentError>(instance_array)
|
||||||
});
|
});
|
||||||
fut.await.into_lua_err()??.into_lua(lua)
|
fut.await.into_lua_err()?.into_lua(lua)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn serialize_place<'lua>(
|
async fn serialize_place<'lua>(
|
||||||
|
@ -67,7 +66,7 @@ async fn serialize_place<'lua>(
|
||||||
(data_model, as_xml): (LuaUserDataRef<'lua, Instance>, Option<bool>),
|
(data_model, as_xml): (LuaUserDataRef<'lua, Instance>, Option<bool>),
|
||||||
) -> LuaResult<LuaString<'lua>> {
|
) -> LuaResult<LuaString<'lua>> {
|
||||||
let data_model = (*data_model).clone();
|
let data_model = (*data_model).clone();
|
||||||
let fut = task::spawn_blocking(move || {
|
let fut = lua.spawn_blocking(move || {
|
||||||
let doc = Document::from_data_model_instance(data_model)?;
|
let doc = Document::from_data_model_instance(data_model)?;
|
||||||
let bytes = doc.to_bytes_with_format(match as_xml {
|
let bytes = doc.to_bytes_with_format(match as_xml {
|
||||||
Some(true) => DocumentFormat::Xml,
|
Some(true) => DocumentFormat::Xml,
|
||||||
|
@ -75,7 +74,7 @@ async fn serialize_place<'lua>(
|
||||||
})?;
|
})?;
|
||||||
Ok::<_, DocumentError>(bytes)
|
Ok::<_, DocumentError>(bytes)
|
||||||
});
|
});
|
||||||
let bytes = fut.await.into_lua_err()??;
|
let bytes = fut.await.into_lua_err()?;
|
||||||
lua.create_string(bytes)
|
lua.create_string(bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +83,7 @@ async fn serialize_model<'lua>(
|
||||||
(instances, as_xml): (Vec<LuaUserDataRef<'lua, Instance>>, Option<bool>),
|
(instances, as_xml): (Vec<LuaUserDataRef<'lua, Instance>>, Option<bool>),
|
||||||
) -> LuaResult<LuaString<'lua>> {
|
) -> LuaResult<LuaString<'lua>> {
|
||||||
let instances = instances.iter().map(|i| (*i).clone()).collect();
|
let instances = instances.iter().map(|i| (*i).clone()).collect();
|
||||||
let fut = task::spawn_blocking(move || {
|
let fut = lua.spawn_blocking(move || {
|
||||||
let doc = Document::from_instance_array(instances)?;
|
let doc = Document::from_instance_array(instances)?;
|
||||||
let bytes = doc.to_bytes_with_format(match as_xml {
|
let bytes = doc.to_bytes_with_format(match as_xml {
|
||||||
Some(true) => DocumentFormat::Xml,
|
Some(true) => DocumentFormat::Xml,
|
||||||
|
@ -92,7 +91,7 @@ async fn serialize_model<'lua>(
|
||||||
})?;
|
})?;
|
||||||
Ok::<_, DocumentError>(bytes)
|
Ok::<_, DocumentError>(bytes)
|
||||||
});
|
});
|
||||||
let bytes = fut.await.into_lua_err()??;
|
let bytes = fut.await.into_lua_err()?;
|
||||||
lua.create_string(bytes)
|
lua.create_string(bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
use lz4_flex::{compress_prepend_size, decompress_size_prepended};
|
|
||||||
use mlua::prelude::*;
|
use mlua::prelude::*;
|
||||||
use tokio::{
|
|
||||||
io::{copy, BufReader},
|
use lz4_flex::{compress_prepend_size, decompress_size_prepended};
|
||||||
task,
|
use tokio::io::{copy, BufReader};
|
||||||
};
|
|
||||||
|
|
||||||
use async_compression::{
|
use async_compression::{
|
||||||
tokio::bufread::{
|
tokio::bufread::{
|
||||||
|
@ -100,9 +98,7 @@ pub async fn compress<'lua>(
|
||||||
) -> LuaResult<Vec<u8>> {
|
) -> LuaResult<Vec<u8>> {
|
||||||
if let CompressDecompressFormat::LZ4 = format {
|
if let CompressDecompressFormat::LZ4 = format {
|
||||||
let source = source.as_ref().to_vec();
|
let source = source.as_ref().to_vec();
|
||||||
return task::spawn_blocking(move || compress_prepend_size(&source))
|
return Ok(blocking::unblock(move || compress_prepend_size(&source)).await);
|
||||||
.await
|
|
||||||
.into_lua_err();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut bytes = Vec::new();
|
let mut bytes = Vec::new();
|
||||||
|
@ -133,9 +129,8 @@ pub async fn decompress<'lua>(
|
||||||
) -> LuaResult<Vec<u8>> {
|
) -> LuaResult<Vec<u8>> {
|
||||||
if let CompressDecompressFormat::LZ4 = format {
|
if let CompressDecompressFormat::LZ4 = format {
|
||||||
let source = source.as_ref().to_vec();
|
let source = source.as_ref().to_vec();
|
||||||
return task::spawn_blocking(move || decompress_size_prepended(&source))
|
return blocking::unblock(move || decompress_size_prepended(&source))
|
||||||
.await
|
.await
|
||||||
.into_lua_err()?
|
|
||||||
.into_lua_err();
|
.into_lua_err();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
use mlua::prelude::*;
|
use mlua::prelude::*;
|
||||||
|
|
||||||
use dialoguer::{theme::ColorfulTheme, Confirm, Input, MultiSelect, Select};
|
use dialoguer::{theme::ColorfulTheme, Confirm, Input, MultiSelect, Select};
|
||||||
use tokio::{
|
use mlua_luau_scheduler::LuaSpawnExt;
|
||||||
io::{self, AsyncWriteExt},
|
use tokio::io::{self, AsyncWriteExt};
|
||||||
task,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::lune::util::{
|
use crate::lune::util::{
|
||||||
formatting::{
|
formatting::{
|
||||||
|
@ -55,10 +53,10 @@ async fn stdio_ewrite(_: &Lua, s: LuaString<'_>) -> LuaResult<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn stdio_prompt(_: &Lua, options: PromptOptions) -> LuaResult<PromptResult> {
|
async fn stdio_prompt(lua: &Lua, options: PromptOptions) -> LuaResult<PromptResult> {
|
||||||
task::spawn_blocking(move || prompt(options))
|
lua.spawn_blocking(move || prompt(options))
|
||||||
.await
|
.await
|
||||||
.into_lua_err()?
|
.into_lua_err()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prompt(options: PromptOptions) -> LuaResult<PromptResult> {
|
fn prompt(options: PromptOptions) -> LuaResult<PromptResult> {
|
||||||
|
|
Loading…
Add table
Reference in a new issue