1
0
forked from ROMEO/nexosim

First public commit

This commit is contained in:
Serge Barral
2022-10-12 05:33:16 +02:00
commit 5c94ec6a65
34 changed files with 5893 additions and 0 deletions

View File

@ -0,0 +1,38 @@
//! Unstable, unofficial public API meant for external benchmarking and testing.
//!
//! Not for production use!
use std::future::Future;
use crate::runtime::executor;
/// A multi-threaded `async` executor.
#[derive(Debug)]
pub struct Executor(executor::Executor);
impl Executor {
/// Creates an executor that runs futures on a thread pool.
///
/// The maximum number of threads is set with the `pool_size` parameter.
pub fn new(pool_size: usize) -> Self {
Self(executor::Executor::new(pool_size))
}
/// Spawns a task which output will never be retrieved.
///
/// This is mostly useful to avoid undue reference counting for futures that
/// return a `()` type.
pub fn spawn_and_forget<T>(&self, future: T)
where
T: Future + Send + 'static,
T::Output: Send + 'static,
{
self.0.spawn_and_forget(future);
}
/// Let the executor run, blocking until all futures have completed or until
/// the executor deadlocks.
pub fn run(&mut self) {
self.0.run();
}
}