File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,18 @@ pub using @coroutine {pause}
4848/// In this case, `is_being_cancelled` can be used to avoid dead loop.
4949pub using @coroutine {is_being_cancelled }
5050
51+ ///|
52+ /// `is_cancellation_error(err)` return `true`
53+ /// if `err` is the special error used to represent cancellation internally.
54+ ///
55+ /// Note that `is_cancellation_error` may not be accurate:
56+ /// async code may fail and raise other error during cancellation handling,
57+ /// in this case the error may be replaced by something else.
58+ /// For accurate detection of cancellation, use `is_being_cancelled` instead.
59+ pub fn is_cancellation_error (error : Error ) -> Bool {
60+ error is @coroutine .Cancelled
61+ }
62+
5163///|
5264pub suberror TimeoutError derive (Show , ToJson )
5365
Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ import(
1010// Values
1111fn is_being_cancelled() -> Bool
1212
13+ fn is_cancellation_error(Error) -> Bool
14+
1315fn now() -> Int64
1416
1517async fn pause() -> Unit
You can’t perform that action at this time.
0 commit comments