use std::sync::Arc;
use crate::scheduler::{Executor, LamellarExecutor, LamellarTask, LamellarTaskInner};
use async_std::task;
use futures_util::Future;
#[derive(Debug)]
pub(crate) struct AsyncStdRt {
max_num_threads: usize,
}
impl LamellarExecutor for AsyncStdRt {
fn spawn_task<F>(&self, task: F, executor: Arc<Executor>) -> LamellarTask<F::Output>
where
F: Future + Send + 'static,
F::Output: Send,
{
let task = task::spawn(task);
LamellarTask {
task: LamellarTaskInner::AsyncStdTask(task),
executor,
task_id: 0,
}
}
fn submit_task<F>(&self, task: F)
where
F: Future + Send + 'static,
F::Output: Send,
{
task::spawn(async move { task.await });
}
fn submit_task_thread<F>(&self, task: F, _: usize)
where
F: Future + Send + 'static,
F::Output: Send,
{
task::spawn(async move { task.await });
}
fn submit_io_task<F>(&self, task: F)
where
F: Future + Send + 'static,
F::Output: Send,
{
task::spawn(async move { task.await });
}
fn submit_immediate_task<F>(&self, task: F)
where
F: Future + Send + 'static,
F::Output: Send,
{
task::spawn(async move { task.await });
}
fn block_on<F: Future>(&self, task: F) -> F::Output {
task::block_on(task)
}
fn shutdown(&self) {
}
fn force_shutdown(&self) {
}
fn exec_task(&self) {
}
fn num_workers(&self) -> usize {
self.max_num_threads
}
}
impl AsyncStdRt {
pub(crate) fn new(num_workers: usize) -> AsyncStdRt {
async_global_executor::init_with_config(
async_global_executor::GlobalExecutorConfig::default()
.with_min_threads(num_workers)
.with_max_threads(num_workers)
.with_thread_name_fn(Box::new(|| "lamellar_worker".to_string())),
);
Self {
max_num_threads: num_workers,
}
}
}