mirror of https://github.com/chipsenkbeil/distant
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
437 B
Rust
18 lines
437 B
Rust
3 years ago
|
use mlua::{chunk, prelude::*};
|
||
|
use std::{thread, time::Duration};
|
||
|
|
||
|
/// Creates a function that can be passed as the schedule function for `wrap_async`
|
||
|
pub fn make_function(lua: &Lua) -> LuaResult<LuaFunction> {
|
||
|
let sleep = lua.create_function(|_, ()| {
|
||
|
thread::sleep(Duration::from_millis(10));
|
||
|
Ok(())
|
||
|
})?;
|
||
|
|
||
|
lua.load(chunk! {
|
||
|
local cb = ...
|
||
|
$sleep()
|
||
|
cb()
|
||
|
})
|
||
|
.into_function()
|
||
|
}
|