Friday 28 May 2010
For anyone interested in following the future direction of ASIHTTPRequest, there’s an experimental version in this branch on GitHub:
You can download it directly here.
The big change from the current version of ASIHTTPRequest is that ASINetworkQueue has been replaced with a new queue that is not based on NSOperationQueue. Instead, it uses a single background thread that runs all requests and blocks when it has nothing to do.
I’ve been exploring the idea of a replacement queue for several reasons:
- Although ASIHTTPRequest doesn’t require the use of an NSOperationQueue for asynchronous operations, there’s currently no way to restrict the maximum number of concurrent operations for requests that don’t run in a queue.
- The thread per request model that the current queue uses may be sub-optimal. We discussed this on the ASIHTTPRequest Google Group back in November, and Jeff LaMarche recently brought this issue up on his blog.
- It has become harder to test ASIHTTPRequest because it supports so many styles of running requests, and the behaviour of NSOperationQueue differs between Mac and iPhone OS.
- There is a fair bit of cruft in ASIHTTPRequest.m that exists for the sole purpose of forcing requests to run in a fashion an NSOperationQueue will like.
The new ASINetworkQueue uses a single background thread that is transparently created the first time you use it. All requests run on this thread. The new queue has an API that’s pretty similar to the old one, and it emulates some of the behaviour of an NSOperationQueue, so it should be fairly easy to port projects over.
What happens next?
I think it’s important to highlight that this is currently an experiment. At this point, it’s hard to say if this queue will replace the current version or not. I don’t want to make a big change like this unless it’s clear that it provides significant benefits.
If anyone has the time and is interested in testing the new queue, I’d appreciate any feedback.
Hopefully this goes without saying, but this experimental version of ASIHTTPRequest is not ready for everyday use. Please do not use it in applications you intend to release.
As a side note, this version of ASIHTTPRequest also includes the forthcoming download cache. If you’d like to know more about this and/or play with it in a more stable version of ASIHTTPRequest, see here.
Posted by Ben @ 3:59 PM