1use std::fmt;
2
3use super::{COMPLETE, RawTask, id::TaskId};
4
5#[derive(Clone)]
6pub struct AbortHandle {
7 pub(super) raw: RawTask,
8}
9
10unsafe impl Send for AbortHandle {}
11unsafe impl Sync for AbortHandle {}
12
13impl AbortHandle {
14 #[inline]
15 pub fn abort(&self) {
16 self.raw.abort_task();
17 }
18
19 #[inline]
20 pub fn is_finished(&self) -> bool {
21 self.raw.header().state.load().has(COMPLETE)
22 }
23
24 #[inline]
25 pub fn id(&self) -> TaskId {
26 TaskId::new(&self.raw)
27 }
28}
29
30impl std::panic::UnwindSafe for AbortHandle {}
31impl std::panic::RefUnwindSafe for AbortHandle {}
32
33impl fmt::Debug for AbortHandle {
34 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
35 fmt.debug_struct("AbortHandle")
36 .field("id", &self.id())
37 .finish()
38 }
39}