0

I'm implementing a download manager in cocoa. The user can add several download requests, and the request manager will show the progress of the requests in a panel. I came into problem about the pause/resume of the request in the queue.

For simplicity, supposing the max concurrent operation count is 1, I add several requests with order:1, 2, 3,4,5. If it is not interrupted, the request is downloaded from 1 to 5 in sequence. Supposing I pause the request 1, the request 2 should continue to download. During that time, I resume the request 1. Hence, after the request 2 is finished, I hope the request 1 can be continued before request 3.

The problem here is that: For the single request when I paused it, the request in fact was cancelled. when I resumed the request, a new request was initialed and then started. In an operation queue, now I sent [self cancel] if the request was paused so that the next request could be started. However, I don't know how to do if it is resumed. The canceled request cannot be added to the queue again. If I created a new one and add it to the queue, how can I promise the priority like the before?

Please give tips on how to do it.

thanks

scorpiozj
  • 2,687
  • 5
  • 34
  • 60

1 Answers1

0

Currently I make a solution myself using:

  1. make a custom request inherited from ASIHttpRequest;
  2. make a NAMutableArray to contain all the requests;
  3. If one request is added, enumerating the array to see if the maximum requests are executing. If not, start the request in its own queue. If exceeding the maximum, just add the request to the array, and set its status to waiting;
  4. If one request is finishing or failing, enumerating the array to see the request which is in the first position by adding time with a status waiting;
scorpiozj
  • 2,687
  • 5
  • 34
  • 60