Skip to content

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

Open
@KaMagno

Description

@KaMagno

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) 
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    FoundationfeatureA feature request or implementationtransfer candidateThe issue may belong in another repository

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions