pub enum JobHandleError {
JobCancelled,
JobPanicked(PanicInfo),
CancelJobError(SendError<()>),
JobResultError(RecvError),
JobResultWrapperError {
from: &'static str,
to: &'static str,
},
}Expand description
a job-handle error.
Variants§
JobCancelled
JobPanicked(PanicInfo)
CancelJobError(SendError<()>)
JobResultError(RecvError)
JobResultWrapperError
Implementations§
Source§impl JobHandleError
impl JobHandleError
Sourcepub fn is_panic(&self) -> bool
pub fn is_panic(&self) -> bool
Returns true if the error was caused by the task panicking.
use neptune_job_queue::JobQueue;
use neptune_job_queue::traits::*;
struct PanicJob;
#[async_trait::async_trait]
impl Job for PanicJob {
fn is_async(&self) -> bool {
true
}
async fn run_async(&self) -> Box<dyn JobResult> {
panic!("{}", "boom");
}
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let job_queue = JobQueue::start();
let job_handle = job_queue.add_job(PanicJob, 1)?;
let err = job_handle.await?.unwrap_err();
assert!(err.is_panic());
Ok(())
}Sourcepub fn into_panic(self) -> Box<dyn Any + Send + 'static>
pub fn into_panic(self) -> Box<dyn Any + Send + 'static>
into_panic() panics if the Error does not represent the underlying task terminating with a panic. Use is_panic to check the error reason or try_into_panic for a variant that does not panic.
ⓘ
use neptune_job_queue::JobQueue;
use neptune_job_queue::traits::*;
struct PanicJob;
#[async_trait::async_trait]
impl Job for PanicJob {
fn is_async(&self) -> bool {
true
}
async fn run_async(&self) -> Box<dyn JobResult> {
panic!("{}", "boom");
}
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let job_queue = JobQueue::start();
let job_handle = job_queue.add_job(PanicJob, 1)?;
let err = job_handle.await?.unwrap_err();
// Resume the panic on the main task
std::panic::resume_unwind(err.into_panic());
Ok(())
}Sourcepub fn try_into_panic(self) -> Result<Box<dyn Any + Send + 'static>, Self>
pub fn try_into_panic(self) -> Result<Box<dyn Any + Send + 'static>, Self>
Consumes the JobHandleError, returning the object with which the task panicked if the task terminated due to a panic. Otherwise, self is returned.
ⓘ
use neptune_job_queue::JobQueue;
use neptune_job_queue::traits::*;
struct PanicJob;
#[async_trait::async_trait]
impl Job for PanicJob {
fn is_async(&self) -> bool {
true
}
async fn run_async(&self) -> Box<dyn JobResult> {
panic!("{}", "boom");
}
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let job_queue = JobQueue::start();
let job_handle = job_queue.add_job(PanicJob, 1)?;
let err = job_handle.await?.unwrap_err();
// Resume the panic on the main task
let panic = err.try_into_panic()?;
std::panic::resume_unwind(panic);
Ok(())
}Sourcepub fn panic_message(&self) -> Option<String>
pub fn panic_message(&self) -> Option<String>
returns panic message, if available
returns None if Error variant is not JobPanicked or panic info cannot
be downcast to a string representation
use neptune_job_queue::JobQueue;
use neptune_job_queue::traits::*;
struct PanicJob;
#[async_trait::async_trait]
impl Job for PanicJob {
fn is_async(&self) -> bool {
true
}
async fn run_async(&self) -> Box<dyn JobResult> {
panic!("{}", "boom");
}
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let job_queue = JobQueue::start();
let job_handle = job_queue.add_job(PanicJob, 1)?;
let err = job_handle.await?.unwrap_err();
assert_eq!( Some("boom".to_string()), err.panic_message());
Ok(())
}Trait Implementations§
Source§impl Debug for JobHandleError
impl Debug for JobHandleError
Source§impl Display for JobHandleError
impl Display for JobHandleError
Source§impl Error for JobHandleError
impl Error for JobHandleError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0:
use the Display impl or to_string()
Source§impl From<RecvError> for JobHandleError
impl From<RecvError> for JobHandleError
Auto Trait Implementations§
impl !Freeze for JobHandleError
impl RefUnwindSafe for JobHandleError
impl Send for JobHandleError
impl Sync for JobHandleError
impl Unpin for JobHandleError
impl UnsafeUnpin for JobHandleError
impl UnwindSafe for JobHandleError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more