use pi_async_task::definitions::BuildErrorKind;
use pi_async_task_queue::{
external::ExternalPushErrorKind, idle::IdleQueueError, local::QueuePushErrorKind,
timer::TimerQueueError,
};
use pi_result::prelude::*;
use std::num::NonZeroU64;
use std::time::Duration;
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
pub struct RuntimeId(NonZeroU64);
impl RuntimeId {
pub fn try_new() -> pi_result::Result<Self> {
runtime_id_new_inner()
}
pub fn get(self) -> u64 {
self.0.get()
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum RuntimeStatus {
Open,
Closing,
Closed,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum IdleState {
Unknown,
Idle,
NotIdle,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum CloseState {
NotRequested,
Requested,
Completed,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum CloseRequestStatus {
Requested,
AlreadyRequested,
AlreadyClosed,
}
#[derive(Debug, ThisError)]
pub enum CurrentRuntimeAccessError {
#[error("没有当前运行时(runtime)环境")]
NoCurrentRuntime,
#[error("当前运行时(runtime)的公开访问类型不匹配")]
TypeMismatch,
#[error("当前范围已选择另一运行时(runtime)")]
DifferentRuntime,
#[error("线程局部存储(TLS)不可访问")]
ContextUnavailable,
}
#[derive(Debug, ThisError)]
pub enum LocalRuntimeAccessError {
#[error("没有当前有效的本地运行时(runtime)")]
NoLocalRuntime,
#[error("本地访问类型(type)不匹配")]
TypeMismatch,
#[error("本地权限已经撤销")]
AccessRevoked,
#[error("线程局部存储(TLS)不可访问")]
ContextUnavailable,
}
pub enum CreateErrorKind {
Task(BuildErrorKind),
LocalContext(LocalRuntimeAccessError),
Timer(TimerError),
}
pub enum SubmitErrorKind {
WrongRuntime,
LocalSubmissionRequired,
OrdinarySubmissionRequired,
WrongOwner,
LocalContext(LocalRuntimeAccessError),
External(ExternalPushErrorKind),
LocalQueue(QueuePushErrorKind),
Idle(IdleQueueError),
Timer(TimerQueueError),
Startup(pi_result::Error),
}
pub enum TimerError {
InvalidDuration {
value: Duration,
min_positive: Duration,
max: Option<Duration>,
},
Clock(pi_result::Error),
DeadlineOutOfRange(pi_result::Error),
RegistrationPreparation(pi_result::Error),
Queue(TimerQueueError),
Cancelled,
RegistrationRemoved,
ServiceClosed,
}
pub enum TimeoutError {
Elapsed,
Timer(TimerError),
}
pub enum WaitTimeoutError {
Wait(pi_async_wait::WaitError),
Elapsed,
Timer(TimerError),
}
macro_rules! error_format {
($ty:ty, $debug:ident, $display:ident) => {
impl std::fmt::Debug for $ty {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
$debug(self, f)
}
}
impl std::fmt::Display for $ty {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
$display(self, f)
}
}
};
}
error_format!(
CreateErrorKind,
create_error_debug_inner,
create_error_display_inner
);
error_format!(
SubmitErrorKind,
submit_error_debug_inner,
submit_error_display_inner
);
error_format!(
TimerError,
timer_error_debug_inner,
timer_error_display_inner
);
error_format!(
TimeoutError,
timeout_error_debug_inner,
timeout_error_display_inner
);
error_format!(
WaitTimeoutError,
wait_timeout_error_debug_inner,
wait_timeout_error_display_inner
);
impl std::error::Error for TimerError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
timer_error_source_inner(self)
}
}
impl TimerError {
pub fn into_report(self) -> pi_result::Error {
timer_error_report_inner(self)
}
}
include!("definitions_inner.rs");