v0.22.0
-
[breaking]
catchcan no longer capture cancellation.In this release,
moonbitlang/asyncchanges how cancellation is signaled for cancelled code. Previously cancellation signal is represented using an ordinarysuberror. In this release, cancellation signal is represented using special compiler primitive. The cancellation signal still propagate likes error and triggersdefer/errdeferlike an error. However,try .. catchcan no longer capture the cancellation signal.The correct way to adapt this change depend on existing code shape:
- code using
defer/errdeferneed no change at all - code using
catchfor cleanup purpose, migrate todefer/errdefer. There should be a compiler warning forcatchhandler that looks likedefer/errdefer. Notice thatdefer/errdefercan containraiseorasynccode now - other kinds of
catchhandler usually should not capture cancellation anyway. For example user should not wrap cancellation signal into another error in general, because that will confuse various structural concurrency combinators. If thecatchhandler previously skip cancellation signal manually viais_cancellation_error, simply remove that special case. If thecatchhandler has no special cancellation handling previously, upgrading to this version may fix buggy behavior on cancellation automatically - when special handling of cancellation is indeed desired, use
@async.handle_cancellation
- code using
-
[breaking]
@async.is_cancellation_errornow always returnfalseand is deprecated, because cancellation signal is no longer a special error. Forcatchhandlers using with special@async.is_cancellation_errorbranch, either delete the branch directly (if the branch is used to prevent cancellation from getting handled like other errors) or use@async.handle_cancellationinstead. -
[breaking]
@async.TaskGroup::add_defernow requires the deferred block to benocancel -
[breaking] add
noraisemask to various API, such as@async.sleep. These functions were previously consideredraisebecause they are cancellable, and cancellation signal was previously an error. In this version, cancellation is now separated from normal error, soasyncAPI that never raise an error themselves, merely cancellable can now receive a more precise type withnoraisemark.This change should be invisible for most users. However code that use affected function as higher order function directly may receive a type error.
-
adapt
nocancelmark in various API. The latest version of MoonBit now provides a newnocancelmark on function signature. Thenocancelmark is added to@async.protect_from_canceland several other inherently non-cancellable API. When usingmoonbitlang/async,nocancelalways mean "not cancellable". Code that capture cancellation signal are still cancellable, and indeed the signature of@async.capture_cancellationdoes not containnocancel -
deprecate
@async.with_cancellation_handler, in favor of a new API@async.handle_cancellation.@async.handle_cancellationruns a cancellableasynccallback, and returnNoneif the callback is cancelled while running. Notice that@async.handle_cancellationonly captures a single cancellation signal, it does not revert cancellation altogether. Current task remain in cancelled state, and subsequent unprotectedasyncoperation still get cancelled immediately -
@fs.removeand@fs.rmdirare made non-cancellable, because they are often used in cleanup operations -
introduce
@async.platformfor runtime OS detection. This is especially useful for Wasm backend, because a single Wasm binary can be run on different operating systems, so the actual OS can only be known at runtime. Currently supported operating systems includeLinux,MacOSandWindows -
bug fix & adapt latest compiler version