mirror of
https://github.com/lune-org/lune.git
synced 2024-12-13 13:30:38 +00:00
Make wait async again
This commit is contained in:
parent
f8a2eb79d4
commit
af0c6d882e
1 changed files with 5 additions and 4 deletions
|
@ -1,6 +1,7 @@
|
||||||
use std::{thread::sleep, time::Duration};
|
use std::time::Duration;
|
||||||
|
|
||||||
use mlua::{Function, Lua, Result, Table, Value};
|
use mlua::{Function, Lua, Result, Table, Value};
|
||||||
|
use tokio::time;
|
||||||
|
|
||||||
use crate::utils::table_builder::ReadonlyTableBuilder;
|
use crate::utils::table_builder::ReadonlyTableBuilder;
|
||||||
|
|
||||||
|
@ -26,15 +27,15 @@ pub async fn new(lua: &Lua) -> Result<Table> {
|
||||||
.with_value("defer", Value::Function(task_defer))?
|
.with_value("defer", Value::Function(task_defer))?
|
||||||
.with_value("delay", Value::Function(task_delay))?
|
.with_value("delay", Value::Function(task_delay))?
|
||||||
.with_value("spawn", Value::Function(task_spawn))?
|
.with_value("spawn", Value::Function(task_spawn))?
|
||||||
.with_function("wait", wait)?
|
.with_async_function("wait", wait)?
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: It does seem possible to properly make an async wait
|
// FIXME: It does seem possible to properly make an async wait
|
||||||
// function with mlua right now, something breaks when using
|
// function with mlua right now, something breaks when using
|
||||||
// async wait functions inside of coroutines
|
// async wait functions inside of coroutines
|
||||||
fn wait(_: &Lua, duration: Option<f32>) -> Result<f32> {
|
async fn wait(_: &Lua, duration: Option<f32>) -> Result<f32> {
|
||||||
let secs = duration.unwrap_or(DEFAULT_SLEEP_DURATION);
|
let secs = duration.unwrap_or(DEFAULT_SLEEP_DURATION);
|
||||||
sleep(Duration::from_secs_f32(secs));
|
time::sleep(Duration::from_secs_f32(secs)).await;
|
||||||
Ok(secs)
|
Ok(secs)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue