-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Concurrency] Import Objective-C methods with completion handlers as async #33674
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
Merged
DougGregor
merged 3 commits into
swiftlang:master
from
DougGregor:concurrency-objc-import-async
Aug 29, 2020
Merged
[Concurrency] Import Objective-C methods with completion handlers as async #33674
DougGregor
merged 3 commits into
swiftlang:master
from
DougGregor:concurrency-objc-import-async
Aug 29, 2020
Conversation
This file contains hidden or 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
This operation is not actually dependent on the version.
5b2f81f
to
3a936bc
Compare
…async When a given Objective-C method has a completion handler parameter with an appropriate signature, import that Objective-C method as async. For example, consider the following CloudKit API: - (void)fetchShareParticipantWithUserRecordID:(CKRecordID *)userRecordID completionHandler:(void (^)(CKShareParticipant * _Nullable shareParticipant, NSError * _Nullable error))completionHandler; With the experimental concurrency model, this would import as: func fetchShareParticipant(withUserRecordID userRecordID: CKRecord.ID) async throws -> CKShare.Participant? The compiler will be responsible for turning the caller's continuation into a block to pass along to the completion handler. When the error parameter of the completion handler is non-null, the async call will result in that error being thrown. Otherwise, the other arguments passed to that completion handler will be returned as the result of the async call. async versions of methods are imported alongside their completion-handler versions, to maintain source compatibility with existing code that provides a completion handler. Note that this only covers the Clang importer portion of this task.
3a936bc
to
1e5d30f
Compare
@swift-ci please smoke test |
@swift-ci please test source compatibility |
…ync import Extend the check for completion handler parameters to also consider the name of the parameter (not its argument label). If it's `completion` or `completionHandler`, we have a completion handler. This extends our API coverage for importing Objective-C methods with completion handlers as 'async'.
@swift-ci please smoke test |
@swift-ci please smoke test Linux |
sigh Linux failure is what @CodaFi is working on fixing in Clang |
@swift-ci please smoke test Linux |
If the async method doesn't end up throwing, then should the return value be non-optional? ie func fetchShareParticipant(withUserRecordID userRecordID: CKRecord.ID) async throws -> CKShare.Participant |
I assume it has to be optional to cover cases where both the result and error are nil. |
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.
When a given Objective-C method has a completion handler parameter
with an appropriate signature, import that Objective-C method as
async. For example, consider the following CloudKit API:
With the experimental concurrency model, this would import as:
The compiler will be responsible for turning the caller's continuation
into a block to pass along to the completion handler. When the error
parameter of the completion handler is non-null, the async call
will result in that error being thrown. Otherwise, the other arguments
passed to that completion handler will be returned as the result of
the async call.
async versions of methods are imported alongside their
completion-handler versions, to maintain source compatibility with
existing code that provides a completion handler.
Note that this only covers the Clang importer portion of this task.