[Concurrency] Add an experimental macro for wrapping a function body in a new task. #79729
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
It's very common to wrap an entire function body in a new task, e.g. in a synchronous event handler that needs to kick off async work. This change adds an experimental function body macro that wraps an entire function body in a task.
This macro is a much simpler version of the
@asyncHandler
attribute, which was proposed in an early pitch of SE-0297: Concurrency Interoperability with Objective-C, and subsetted out because many event handlers need to start work synchronously. This macro currently usesTask.init
, but could be updated to use the pitchedTask.startSynchronously
API.This macro is gated behind the
ConcurrencySyntaxSugar
experimental feature. I'll write up a pitch for this soon to discuss the design. Please save any design feedback for the forthcoming forum thread.I'm currently working on lifting the limitation that function body macros cannot be applied to closures, so this macro can be used with closures too. There are quite a few places that assume an attached macro can only be applied to a declaration :)