Add an AsyncExecutor trait for background tasks
This commit is contained in:
parent
558922c9a9
commit
25d20f1950
23
src/async_executor.rs
Normal file
23
src/async_executor.rs
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
//! Traits for running background tasks from a [`Plugin`][crate::prelude::Plugin].
|
||||||
|
//!
|
||||||
|
//! This should not be confused with the `async` language features and ecosystem in Rust.
|
||||||
|
|
||||||
|
/// Something that can run tasks of type [`Task`][Self::Task]. This can be used to defer expensive
|
||||||
|
/// computations to a background thread. Tasks can be spawned through the methods on the various
|
||||||
|
/// [`*Context`][crate::context] types.
|
||||||
|
pub trait AsyncExecutor {
|
||||||
|
/// The type of task this executor can execute. This is usually an enum type. The task type
|
||||||
|
/// should not contain any heap allocated data like [`Vec`]s and [`Box`]es.
|
||||||
|
type Task;
|
||||||
|
|
||||||
|
/// Run `task` on the current thread. This is usually called from the operating system's main
|
||||||
|
/// thread or a similar thread.
|
||||||
|
fn execute(&self, task: Self::Task);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A default implementation for plugins that don't need asynchronous background tasks.
|
||||||
|
impl AsyncExecutor for () {
|
||||||
|
type Task = ();
|
||||||
|
|
||||||
|
fn execute(&self, _task: Self::Task) {}
|
||||||
|
}
|
|
@ -101,6 +101,7 @@ pub mod prelude;
|
||||||
pub mod formatters;
|
pub mod formatters;
|
||||||
pub mod util;
|
pub mod util;
|
||||||
|
|
||||||
|
pub mod async_executor;
|
||||||
pub mod buffer;
|
pub mod buffer;
|
||||||
pub mod context;
|
pub mod context;
|
||||||
pub mod editor;
|
pub mod editor;
|
||||||
|
|
|
@ -10,6 +10,7 @@ pub use crate::wrapper::standalone::{nih_export_standalone, nih_export_standalon
|
||||||
pub use crate::formatters;
|
pub use crate::formatters;
|
||||||
pub use crate::util;
|
pub use crate::util;
|
||||||
|
|
||||||
|
pub use crate::async_executor::AsyncExecutor;
|
||||||
pub use crate::buffer::Buffer;
|
pub use crate::buffer::Buffer;
|
||||||
pub use crate::context::{GuiContext, InitContext, ParamSetter, PluginApi, ProcessContext};
|
pub use crate::context::{GuiContext, InitContext, ParamSetter, PluginApi, ProcessContext};
|
||||||
// This also includes the derive macro
|
// This also includes the derive macro
|
||||||
|
|
Loading…
Reference in a new issue