mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-10-01 12:20:39 +00:00
Make JoinError Sync (#1888)
* Make JoinError Sync * Move Mutex inside JoinError internals, hide its constructors * Deprecate JoinError constructors, fix internal usages
This commit is contained in:
parent
8bcbe78dbe
commit
cbe369a3ed
@ -1,6 +1,7 @@
|
|||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::io;
|
use std::io;
|
||||||
|
use std::sync::Mutex;
|
||||||
|
|
||||||
doc_rt_core! {
|
doc_rt_core! {
|
||||||
/// Task failed to execute to completion.
|
/// Task failed to execute to completion.
|
||||||
@ -11,21 +12,31 @@ doc_rt_core! {
|
|||||||
|
|
||||||
enum Repr {
|
enum Repr {
|
||||||
Cancelled,
|
Cancelled,
|
||||||
Panic(Box<dyn Any + Send + 'static>),
|
Panic(Mutex<Box<dyn Any + Send + 'static>>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl JoinError {
|
impl JoinError {
|
||||||
/// Create a new `cancelled` error
|
#[doc(hidden)]
|
||||||
|
#[deprecated]
|
||||||
pub fn cancelled() -> JoinError {
|
pub fn cancelled() -> JoinError {
|
||||||
|
Self::cancelled2()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn cancelled2() -> JoinError {
|
||||||
JoinError {
|
JoinError {
|
||||||
repr: Repr::Cancelled,
|
repr: Repr::Cancelled,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new `panic` error
|
#[doc(hidden)]
|
||||||
|
#[deprecated]
|
||||||
pub fn panic(err: Box<dyn Any + Send + 'static>) -> JoinError {
|
pub fn panic(err: Box<dyn Any + Send + 'static>) -> JoinError {
|
||||||
|
Self::panic2(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn panic2(err: Box<dyn Any + Send + 'static>) -> JoinError {
|
||||||
JoinError {
|
JoinError {
|
||||||
repr: Repr::Panic(err),
|
repr: Repr::Panic(Mutex::new(err)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
self.complete(executor, join_interest, Err(JoinError::panic(err)));
|
self.complete(executor, join_interest, Err(JoinError::panic2(err)));
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -192,7 +192,7 @@ where
|
|||||||
state: Snapshot,
|
state: Snapshot,
|
||||||
) {
|
) {
|
||||||
if state.is_canceled() {
|
if state.is_canceled() {
|
||||||
dst.write(Track::new(Err(JoinError::cancelled())));
|
dst.write(Track::new(Err(JoinError::cancelled2())));
|
||||||
} else {
|
} else {
|
||||||
self.core().read_output(dst);
|
self.core().read_output(dst);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user