kean / Get

Web API client built using async/await
MIT License
937 stars 74 forks source link

URLSession asyncData implementation for older OS versions #3

Closed vox-humana closed 2 years ago

vox-humana commented 2 years ago

Custom implementation of a compatible async URLSession method for using on older OS versions.

  1. Doesn't include URLSessionDelegate
  2. Not sure about thread safety of URLSessionTask access. Initial proposal didn't require any wrapper. However, in the current implementation compiler doesn't allow to capture mutable URLSessionTask directly.
  3. Haven't tested all platforms but on macOS 11 it passed all tests.

Requires Xcode 13.2 beta 2

You can now use Swift Concurrency in applications that deploy to macOS 10.15, iOS 13, tvOS 13, and watchOS 6 or newer. This support includes async/await, actors, global actors, structured concurrency, and the task APIs. (70738378)

https://developer.apple.com/documentation/xcode-release-notes/xcode-13_2-release-notes

kean commented 2 years ago

Thanks, @vox-humana. That's a good start.

I'm thinking of eventually switching to a delegate-based approach. Without it, unlike the new async APIs, there is no way to get URLSession callbacks. I want to make Pulse integration easy.

vox-humana commented 2 years ago

Totally understand your point about delegate-based API and further Pulse integration. Here I just wanted to illustrate in code what was mentioned in this thread, closing the PR for now.