From af0c6d882e4e3300aaa14c088d922b52a8c6f969 Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Sun, 22 Jan 2023 14:39:57 -0500 Subject: [PATCH] Make wait async again --- src/lib/globals/task.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/lib/globals/task.rs b/src/lib/globals/task.rs index 8acda69..52ebf45 100644 --- a/src/lib/globals/task.rs +++ b/src/lib/globals/task.rs @@ -1,6 +1,7 @@ -use std::{thread::sleep, time::Duration}; +use std::time::Duration; use mlua::{Function, Lua, Result, Table, Value}; +use tokio::time; use crate::utils::table_builder::ReadonlyTableBuilder; @@ -26,15 +27,15 @@ pub async fn new(lua: &Lua) -> Result { .with_value("defer", Value::Function(task_defer))? .with_value("delay", Value::Function(task_delay))? .with_value("spawn", Value::Function(task_spawn))? - .with_function("wait", wait)? + .with_async_function("wait", wait)? .build() } // FIXME: It does seem possible to properly make an async wait // function with mlua right now, something breaks when using // async wait functions inside of coroutines -fn wait(_: &Lua, duration: Option) -> Result { +async fn wait(_: &Lua, duration: Option) -> Result { let secs = duration.unwrap_or(DEFAULT_SLEEP_DURATION); - sleep(Duration::from_secs_f32(secs)); + time::sleep(Duration::from_secs_f32(secs)).await; Ok(secs) }