#[allow(unused_variables)]
fn runtime_new_inner<M, E, I, F, T>(
options: RuntimeOptions,
queues: RuntimeQueues<ManualClock, E, I, F>,
) -> pi_result::Result<ConfiguredRuntime<M, ManualClock, DefaultIdlePolicy, NoHooks, E, I, T>>
where
M: RuntimeMode,
E: ExternalQueueManager,
I: IdleQueueManager,
T: ExecutorTimer<Instant = GlobalManualInstant> + 'static,
F: FnOnce(RuntimeId, &ManualClock, ThreadNotifier, CancelTimerOptions) -> pi_result::Result<T>,
{
let clock = pi_async_executor::ManualClock::new()?;
runtime_components_inner::<M, pi_async_executor::ManualClock, pi_async_executor::DefaultIdlePolicy, pi_async_executor::NoHooks, E, I, F, T>(
clock,
pi_async_executor::DefaultIdlePolicy,
pi_async_executor::NoHooks,
options,
queues,
)
}
#[allow(unused_variables)]
fn runtime_components_inner<M, C, P, H, E, I, F, T>(
clock: C,
policy: P,
hooks: H,
options: RuntimeOptions,
queues: RuntimeQueues<C, E, I, F>,
) -> pi_result::Result<ConfiguredRuntime<M, C, P, H, E, I, T>>
where
M: RuntimeMode,
C: ExecutorClock<Instant = GlobalManualInstant>,
E: ExternalQueueManager,
I: IdleQueueManager,
T: ExecutorTimer<Instant = GlobalManualInstant> + 'static,
P: IdlePolicy,
H: ExecutorHooks,
F: FnOnce(RuntimeId, &C, ThreadNotifier, CancelTimerOptions) -> pi_result::Result<T>,
{
use crate::{
binding::RuntimeTag,
lifecycle::{RuntimeBinding, RuntimeExternalSource},
queues::QueueSelection,
};
let binding = RuntimeBinding::new();
let executor_options = options.executor;
let timer_options = options.timer;
let external = match queues.external {
QueueSelection::Specified(value) => value,
QueueSelection::Default(make) => make(options.external_queue)?,
};
let idle = match queues.idle {
QueueSelection::Specified(value) => value,
QueueSelection::Default(make) => make(options.idle_queue)?,
};
let source = RuntimeExternalSource::new(external, Rc::clone(&binding));
let mut make_timer = Some(queues.timer);
let executor = DefaultExecutor::<
C,
RuntimeExternalSource<E>,
I,
T,
RuntimeTag<C, T>,
>::new(
clock,
source,
idle,
executor_options,
move |runtime, clock, notifier| {
let make = make_timer.take().expect("定时构造回调只执行一次");
make(runtime, clock, notifier, timer_options)
},
)?;
let handle = executor.handle();
let shared = RuntimeHandle { inner: Arc::new(handle) };
let data = RuntimeData {
executor,
mode: M::default(),
policy,
hooks,
};
Ok(ConfiguredRuntime {
shared,
data: RefCell::new(Some(data)),
binding,
})
}
#[allow(unused_variables)]
fn runtime_handle_clone_inner<C, E, I, T>(this: &RuntimeHandle<C, E, I, T>) -> RuntimeHandle<C, E, I, T>
where
C: ExecutorClock<Instant = GlobalManualInstant>,
E: ExternalTaskQueue,
I: IdleTaskQueue,
T: ExecutorTimer<Instant = GlobalManualInstant> + 'static,
{
RuntimeHandle { inner: std::sync::Arc::clone(&this.inner) }
}
#[allow(unused_variables)]
fn runtime_drop_inner<M, C, P, H, E, I, T>(this: &mut ConfiguredRuntime<M, C, P, H, E, I, T>)
where
M: RuntimeMode,
C: ExecutorClock<Instant = GlobalManualInstant>,
E: ExternalQueueManager,
I: IdleQueueManager,
T: ExecutorTimer<Instant = GlobalManualInstant> + 'static,
P: IdlePolicy,
H: ExecutorHooks,
{
this.binding.revoke();
let data = this.data.get_mut().take();
drop(data);
}