-
Notifications
You must be signed in to change notification settings - Fork 10.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Concurrency] Alternative Task API #37680
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The `Task` type has oscillated somewhat from being purely a namespace, to having instances that are used (albeit rarely), back to purely being a namespace that isn't used for all that many names. Many of the names that used to be on Task have already been moved out, e.g., for creating new detached tasks, creating new task groups, adding cancellation handlers, etc. Collapse `Task.Handle<Success, Failure>` into `Task<Success, Failure>`. `Task.Handle` is the type that is most frequently referenced in the concurrency library, so giving it the short name `Task` is most appropriate. Replace the top-level async/detach functions with a `Task` initializer and `Task.detached`, respectively. The `Task` type can still act as a namespace for static operations such as, e.g., `Task.isCancelled`. Do this with an extension of the form: extension Task where Success == Never, Failure == Never { ... } We've been accruing a number of compatibility shims. Move them all into their own source file, deprecate them, and make them always-emit-into-client so they don't have any ABI impact. (cherry picked from commit eda5b4d)
(cherry picked from commit fdee0ff)
(cherry picked from commit 6aefea0)
Based on feedback from the second review, we decided to go with high/default/low/background, with aliases for the Dispatch-inspired names. While here, make TaskPriority be backed by a UInt8 to better describe the actual restrictions, and start removing userInteractive, because clients shouldn't be able to specify it. (cherry picked from commit 8750f20)
Swap the order of the arguments so we now have: await withTaskCancellationHandler { // do stuff } onCancel: { // .. } (cherry picked from commit 72d8197)
(cherry picked from commit 7d2ce77)
@swift-ci please test |
ktoso
approved these changes
May 28, 2021
airspeedswift
approved these changes
May 28, 2021
airspeedswift
approved these changes
May 28, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The
Task
type has oscillated somewhat from being purely a namespace,to having instances that are used (albeit rarely), back to purely
being a namespace that isn't used for all that many names. Many of the
names that used to be on Task have already been moved out, e.g., for
creating new detached tasks, creating new task groups, adding
cancellation handlers, etc.
Collapse
Task.Handle<Success, Failure>
intoTask<Success, Failure>
.Task.Handle
is the type that is most frequently referenced in theconcurrency library, so giving it the short name
Task
is mostappropriate. Replace the top-level async/detach functions with a
Task
initializer andTask.detached
, respectively.The
Task
type can still act as a namespace for static operationssuch as, e.g.,
Task.isCancelled
. Do this with an extension of theform:
We've been accruing a number of compatibility shims. Move them all
into their own source file, deprecate them, and make them
always-emit-into-client so they don't have any ABI impact.
This also covers other changes that came up in the review:
get()
tovalue
as an async propertygetResult()
toresult
as an async propertywithTaskCancellationHandler
parametersTaskPriority
members, and make it aRawRepresentable
structAddresses rdar://78269970