Skip to content
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

Swift Concurrency Support #3463

Merged
merged 17 commits into from
Dec 13, 2021
Merged

Swift Concurrency Support #3463

merged 17 commits into from
Dec 13, 2021

Conversation

jshier
Copy link
Contributor

@jshier jshier commented Jun 8, 2021

Goals ⚽

This PR tracks the implementation of Swift Concurrency support as an extension to Alamofire. This ensures it remains buildable on all platforms.

Implementation Details 🚧

Additions:

  • DataTask, which encapsulates the originating DataRequest and a Task which tracks an underlying continuation for async work. It also provides async access to the response, result, and value properties, as well as read-only access to the properties of the underlying DataRequest.
  • DownloadTask, which does the same for DownloadRequest.
  • DataStreamTask, which encapsulates a DataStreamRequest and vends custom StreamOf values for the stream output. Unlike the data and download cases, this task doesn't trigger the request immediately, only once a stream has been requested.

Testing Details 🔍

Tests added for all task types.

@Tlz-1994
Copy link

Tlz-1994 commented Jun 9, 2021

所以这个 async/await 的特性只能用在 iOS15+ 吗?

@jshier
Copy link
Contributor Author

jshier commented Jun 9, 2021

Right now, yes, the Swift Concurrency features are only available on the 2021 OS versions.

Copy link

@Tlz-1994 Tlz-1994 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

‎现在,是的,Swift 并发功能仅在 2021 OS 版本上提供。‎

It's hard to understand why this feature wasn't embedded in Swift5.5,
why do you think it was bundled with the OS.

Source/Async.swift Outdated Show resolved Hide resolved
@jshier
Copy link
Contributor Author

jshier commented Jun 10, 2021

It's hard to understand why this feature wasn't embedded in Swift5.5,
why do you think it was bundled with the OS.

You can read more about the issue on the Swift Forums.

@Tlz-1994
Copy link

It's hard to understand why this feature wasn't embedded in Swift5.5,
why do you think it was bundled with the OS.

You can read more about the issue on the Swift Forums.

Wow, thanks for your reply.

Source/Async.swift Outdated Show resolved Hide resolved
@afern247
Copy link

afern247 commented Aug 7, 2021

@jshier jshier force-pushed the feature/async-handlers branch 3 times, most recently from 7034f95 to 3784cf7 Compare September 21, 2021 00:22
@Flatout73
Copy link

Any ETA when it will be merged? btw, now concurrency will be supported from iOS 13 since xcode 13.2.

@jshier
Copy link
Contributor Author

jshier commented Nov 3, 2021

Right now I'm aiming to release before Xcode 13.2 ships so we can require it for the Concurrency support. However, this is pending proper test integration, which I'm having some trouble with, so hopefully we'll have some fixes in Xcode 13.2 as well.

@jshier
Copy link
Contributor Author

jshier commented Nov 5, 2021

The recent update to this branch requires Xcode 13.2, as there's no way to deploy versions of async code that can deploy back to the 2019 OSes and the original deployment targets at the same time. Naming has also been updated, as well as the addition of configurable cancellation handling. I hope to round out the various types of support soon.

@horatiu03
Copy link

Will there be some example code on how async should/inteaded to be used with Alamofire?

@jshier
Copy link
Contributor Author

jshier commented Nov 5, 2021

Yes, updated docs will be part of this PR.

@jshier jshier marked this pull request as ready for review November 28, 2021 05:01
@flowbe
Copy link

flowbe commented Dec 10, 2021

Hello,
Now that Xcode 13.2 is in RC, will this be merged soon?

@jshier
Copy link
Contributor Author

jshier commented Dec 12, 2021

I've added some summary documentation to our AdvancedUsage document, as well as extensive inline documentation. Please let be know if there are any additional questions that can be answered in the docs.

This work will be merged and released as soon after the release of Xcode 13.2 as I can manage.

Copy link
Member

@cnoon cnoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great @jshier! Great work across the board!

@jshier jshier merged commit 0c3780e into master Dec 13, 2021
@jshier jshier deleted the feature/async-handlers branch December 13, 2021 22:28
@jshier jshier added this to the 5.5.0 milestone Dec 13, 2021
jshier added a commit that referenced this pull request Jan 15, 2022
* Add Concurrency support.

* Remove misleading Protected convenience APIs.

* Safer NSLog usage.

* Project updates.

* Disable thread sanitizer during development.

* Update tests for new APIs.

* Add concurrency tester.

* Fix concurrency runner.

* 15.2 simulator for concurrency tests.

* Disable thread sanitizer on iOS as well.

* Update inline docs, add stream cancellation.

* Add documentation.

* Document async value handlers.

* Remove TODO.

* Add doc comment.

* Target the concurrent queue for the streams.

* Rename finishObservers to finishHandlers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants