Any API to iterate through all the running Alamofire task?

Does Alamofire have any API to iterate though all the running tasks?

I read through the documents on github, there seems nothing related to this use case.
I know I can maintain the taks list myself. But, if it's already in Alamofire, please let me know.

What, exactly, is your use case? Alamofire currently has the ability to cancel all ongoing requests, and there’s a PR up to add a general iteration API, but it’s use should be rare. It would be good to know what you need here.

Hi, thanks for reply. I want to show a list of all the downloading tasks. Typically, I need the progress ratio of all the tasks. And probably, I need the local URL of all the downloaded files. If there is an API for this, I will save my time from tracking all the different states.

I just found out there is an API from URLSession which could get all the running tasks, but it's asynchronously. That's not good if I want update a GUI list, while maybe I will use it.

func getAllTasks(completionHandler: @escaping ([URLSessionTask]) -> Void)

A simple property won't be enough to accomplish what you want. Really what you'd need is an observable set of active Requests. This isn't really something Alamofire could offer directly but I think you could build it yourself using Alamofire's EventMonitor protocol. Just listen for the right events and update the observable collection yourself.

Terms of Service

Privacy Policy

Cookie Policy