mirror of
https://github.com/lune-org/mlua-luau-scheduler.git
synced 2025-04-10 21:40:55 +01:00
Separate the runtime and spawn traits since runtime should rarely be used
This commit is contained in:
parent
ecbb9dcef8
commit
194cf40f21
3 changed files with 15 additions and 4 deletions
|
@ -6,7 +6,7 @@ use async_fs::read_to_string;
|
||||||
use async_io::block_on;
|
use async_io::block_on;
|
||||||
|
|
||||||
use mlua::prelude::*;
|
use mlua::prelude::*;
|
||||||
use mlua_luau_runtime::{LuaRuntimeExt, Runtime};
|
use mlua_luau_runtime::{LuaSpawnExt, Runtime};
|
||||||
|
|
||||||
const MAIN_SCRIPT: &str = include_str!("./lua/basic_spawn.luau");
|
const MAIN_SCRIPT: &str = include_str!("./lua/basic_spawn.luau");
|
||||||
|
|
||||||
|
|
|
@ -13,4 +13,4 @@ pub use functions::Functions;
|
||||||
pub use runtime::Runtime;
|
pub use runtime::Runtime;
|
||||||
pub use status::Status;
|
pub use status::Status;
|
||||||
pub use thread_id::ThreadId;
|
pub use thread_id::ThreadId;
|
||||||
pub use traits::{IntoLuaThread, LuaRuntimeExt};
|
pub use traits::{IntoLuaThread, LuaRuntimeExt, LuaSpawnExt};
|
||||||
|
|
|
@ -71,8 +71,6 @@ where
|
||||||
- Setting the exit code and forcibly stopping the runtime
|
- Setting the exit code and forcibly stopping the runtime
|
||||||
- Pushing (spawning) and deferring (pushing to the back) lua threads
|
- Pushing (spawning) and deferring (pushing to the back) lua threads
|
||||||
- Tracking and getting the result of lua threads
|
- Tracking and getting the result of lua threads
|
||||||
- Spawning thread-local (`!Send`) futures on the current executor
|
|
||||||
- Spawning background (`Send`) futures on the current executor
|
|
||||||
*/
|
*/
|
||||||
pub trait LuaRuntimeExt<'lua> {
|
pub trait LuaRuntimeExt<'lua> {
|
||||||
/**
|
/**
|
||||||
|
@ -144,7 +142,18 @@ pub trait LuaRuntimeExt<'lua> {
|
||||||
Panics if called outside of a running [`Runtime`].
|
Panics if called outside of a running [`Runtime`].
|
||||||
*/
|
*/
|
||||||
fn wait_for_thread(&'lua self, id: ThreadId) -> impl Future<Output = ()>;
|
fn wait_for_thread(&'lua self, id: ThreadId) -> impl Future<Output = ()>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Trait for interacting with the [`Executor`] for the current [`Runtime`].
|
||||||
|
|
||||||
|
Provides extra methods on the [`Lua`] struct for:
|
||||||
|
|
||||||
|
- Spawning thread-local (`!Send`) futures on the current executor
|
||||||
|
- Spawning background (`Send`) futures on the current executor
|
||||||
|
- Spawning blocking tasks on a separate thread pool
|
||||||
|
*/
|
||||||
|
pub trait LuaSpawnExt<'lua> {
|
||||||
/**
|
/**
|
||||||
Spawns the given future on the current executor and returns its [`Task`].
|
Spawns the given future on the current executor and returns its [`Task`].
|
||||||
|
|
||||||
|
@ -325,7 +334,9 @@ impl<'lua> LuaRuntimeExt<'lua> for Lua {
|
||||||
.expect("lua threads results can only be retrieved within a runtime");
|
.expect("lua threads results can only be retrieved within a runtime");
|
||||||
async move { map.listen(id).await }
|
async move { map.listen(id).await }
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'lua> LuaSpawnExt<'lua> for Lua {
|
||||||
fn spawn<F, T>(&self, fut: F) -> Task<T>
|
fn spawn<F, T>(&self, fut: F) -> Task<T>
|
||||||
where
|
where
|
||||||
F: Future<Output = T> + Send + 'static,
|
F: Future<Output = T> + Send + 'static,
|
||||||
|
|
Loading…
Add table
Reference in a new issue