Skip to content

Commit e929d6e

Browse files
committed
add @async.is_being_cancelled
1 parent 354b249 commit e929d6e

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/async.mbt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ pub using @event_loop {sleep}
3838
/// `pause` can be used to avoid starving other tasks.
3939
pub using @coroutine {pause}
4040

41+
///|
42+
/// Returns `true` if current task is being cancelled.
43+
/// In this case, all work should be stopped except cleanup jobs.
44+
/// Usually there is no need to check for cancellation manually,
45+
/// the cancellation error will automatically get things done.
46+
/// However, some patterns, such as writing catch all error handler
47+
/// inside loop body, may result in infinite loop on cancellation.
48+
/// In this case, `is_being_cancelled` can be used to avoid dead loop.
49+
pub using @coroutine {is_being_cancelled}
50+
4151
///|
4252
pub suberror TimeoutError derive(Show)
4353

src/pkg.generated.mbti

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import(
88
)
99

1010
// Values
11+
fn is_being_cancelled() -> Bool
12+
1113
fn now() -> Int64
1214

1315
async fn pause() -> Unit

0 commit comments

Comments
 (0)