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

Be able to cancel a request when using async await functions of URLSession #69261

Open
KaMagno opened this issue Oct 19, 2023 · 2 comments
Open
Labels
feature A feature request or implementation Foundation transfer candidate The issue may belong in another repository

Comments

@KaMagno
Copy link

KaMagno commented Oct 19, 2023

Motivation
When changing to use async await functions from URLSession I noticed that we lost access to URLSessionDataTask which is necessary when we need to cancel a request. And we need this kind of function especially when working with Feed screens and things alike.

Solution
We already can create an URLSessionDataTask but we don't have an async await function to perform it so my solution would be to add a function that performs URLSessionDataTask and the result would be the same (Data, Response) tulple

extension URLSession {
   func perform(dataTask: URLSessionDataTask) async -> (Data, Response) 
}

Alternatives considered
Another solution would be to add this perform async await function at the URLSessionDataTask as the resume function that it already has but in this case, would be an async await function

extension URLSessionDataTask {
   func resume() async -> (Data, Response) 
}
@KaMagno KaMagno added feature A feature request or implementation triage needed This issue needs more specific labels labels Oct 19, 2023
@jshier
Copy link
Contributor

jshier commented Oct 21, 2023

Foundation's solution here was to provide the urlSession(_:didCreateTask:) URLSessionTaskDelegate method. You could probably create your desired API on top of that method.

@AnthonyLatsis
Copy link
Collaborator

@shahmishal Could we transfer this to the swift-foundation repository?

@AnthonyLatsis AnthonyLatsis added Foundation transfer candidate The issue may belong in another repository and removed triage needed This issue needs more specific labels labels Nov 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A feature request or implementation Foundation transfer candidate The issue may belong in another repository
Projects
None yet
Development

No branches or pull requests

3 participants