From 9c27057bf3aabf09a50c3cfb3f478ae703bb5fe7 Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Sun, 14 Jan 2024 09:38:56 +0100 Subject: [PATCH] Use blocking io for print and warn globals --- src/lune/globals/print.rs | 18 +++++------------- src/lune/globals/warn.rs | 18 +++++------------- 2 files changed, 10 insertions(+), 26 deletions(-) diff --git a/src/lune/globals/print.rs b/src/lune/globals/print.rs index dfdacfd..944d420 100644 --- a/src/lune/globals/print.rs +++ b/src/lune/globals/print.rs @@ -1,23 +1,15 @@ +use std::io::Write as _; + use mlua::prelude::*; -use tokio::{ - io::{self, AsyncWriteExt}, - task, -}; use crate::lune::util::formatting::pretty_format_multi_value; pub fn create(lua: &Lua) -> LuaResult> { lua.create_function(|_, args: LuaMultiValue| { let formatted = format!("{}\n", pretty_format_multi_value(&args)?); - task::spawn(async move { - let _res = async move { - let mut stdout = io::stdout(); - stdout.write_all(formatted.as_bytes()).await?; - stdout.flush().await?; - Ok::<_, LuaError>(()) - }; - // FUTURE: Send any error back to scheduler and emit it properly - }); + let mut stdout = std::io::stdout(); + stdout.write_all(formatted.as_bytes())?; + stdout.flush()?; Ok(()) }) } diff --git a/src/lune/globals/warn.rs b/src/lune/globals/warn.rs index 5a4c303..dfc409e 100644 --- a/src/lune/globals/warn.rs +++ b/src/lune/globals/warn.rs @@ -1,8 +1,6 @@ +use std::io::Write as _; + use mlua::prelude::*; -use tokio::{ - io::{self, AsyncWriteExt}, - task, -}; use crate::lune::util::formatting::{format_label, pretty_format_multi_value}; @@ -13,15 +11,9 @@ pub fn create(lua: &Lua) -> LuaResult> { format_label("warn"), pretty_format_multi_value(&args)? ); - task::spawn(async move { - let _res = async move { - let mut stdout = io::stderr(); - stdout.write_all(formatted.as_bytes()).await?; - stdout.flush().await?; - Ok::<_, LuaError>(()) - }; - // FUTURE: Send any error back to scheduler and emit it properly - }); + let mut stderr = std::io::stderr(); + stderr.write_all(formatted.as_bytes())?; + stderr.flush()?; Ok(()) }) }