Alamofire Priority Queue

I am using Alamofire as my networking library for my Swift application. Is there a way to keep a "priority queue" for network requests using Alamofire? I believe I have seen this function in the library in the past, but I can no longer find it or find other posts about it.

Let's say I open a page in my application and run multiple requests. It gets some JSON first, which is fast and hassle-free.

From this JSON, it extracts some information and then starts loading images. These images can be quite large and take many seconds (~ 30 seconds or more sometimes). But the tricky part is that the user is able to navigate to the next page before the image has finished loading.

If the user navigates to the next page before the image upload is loaded, is it possible to move it to a lower priority queue? So when the images on the next page start loading, will they go faster? I would even be willing to completely suspend the old one until new requests are completed, if possible.

Keep in mind that I am open to many suggestions. I have a lot of freedom with my implementation. So if it's a different library or a different mechanism in iOS, that's fine. Even if I continue to use Alamofire for JSON and do all my image uploads and manipulation with something else, that will be fine too.

Also, it may not matter, but I'll add it here. I am using to cache my images after they are fully loaded. This is why I don't want to completely cancel the request. I need this to end, and then it won't happen again.

TL; DR I want a fast queue and a slow queue with the ability to move things from the fast queue to the slow queue before they are finished.


source to share

1 answer

Have you considered managing NSOperationQueue? You might find this tutorial helpful. In its example, it pauses the load when the page is scrolled, but I believe you can set the queuePriority property of the NSOperation objects instead.



All Articles