1

It is possible to receive progress updates about a URLSessionTask by implementing the URLSessionDataDelegate.urlSession(_:dataTask:didReceive:) delegate method, and using the delegate-style "task, task.resume()" style of invocation.

With the Combine flavor of the API, this does not appear to be possible. Using URLSession.dataTaskPublisher(for:) returns a publisher that publishes the (Data, URLResponse) tuple upon completion, but never invokes the delegate method. In that way, it is very similar to the URLSession.dataTask(with:completionHandler:) method, which invokes completionHandler with the final result, and not in-process Progress reports.

Am I missing any API or pattern to allow progress reporting, or does the Combine flavor of URLSession task handling not offer a way to retrieve progress?

1 Answer 1

5

No, you're not missing anything. To retrieve the progress information you would need to construct your own Future and not use the built-in data task publisher.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for confirming. Have you seen any useful patterns for publishing more than one stream from an API? I'm currently looking at returning an object with various *publisher properties (e.g., resultPublisher, progressPublisher), which feels icky. The other thing I'm considering is accepting a PassthroughSubject<Progress, Never> on the API for interested folks to be notified, but again...icky.
Actually I don't see why result publisher and progress publisher are icky.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.