apple / swift-corelibs-foundation

The Foundation Project, providing core utilities, internationalization, and OS independence
swift.org
Apache License 2.0
5.23k stars 1.12k forks source link

Add async URLSession methods #4970

Closed jrflat closed 4 weeks ago

jrflat commented 1 month ago

Thanks to @b1ackturtle for providing the foundation of this work in #4705!

This PR implements the remaining async URLSession methods and the URLSessionTask.delegate property, allowing a delegate to be set in the async methods (or in a non-async context before resumption). URLSessionTask.delegate returns the explicitly set delegate if present, otherwise returns the session delegate as? URLSessionTaskDelegate. It's now used wherever we previously casted the session delegate to URLSessionTaskDelegate. To accompany this change, functions in extension URLSessionTaskDelegate (which are called if not implemented by the task's delegate) now check if the session's delegate implements it and call the session's delegate if that's the case.

jrflat commented 1 month ago

@swift-ci please test