• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Async NSURLConnection + Concurrent NSOperation = Not possible under Mac OS X 10.6?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Async NSURLConnection + Concurrent NSOperation = Not possible under Mac OS X 10.6?


  • Subject: Re: Async NSURLConnection + Concurrent NSOperation = Not possible under Mac OS X 10.6?
  • From: "Adam R. Maxwell" <email@hidden>
  • Date: Sun, 30 Aug 2009 11:47:51 -0700


On Aug 30, 2009, at 10:18 AM, Ken Thomases wrote:

On Aug 30, 2009, at 10:29 AM, Steven Degutis wrote:

I either would need to use NSURLConnection in a stand-alone class, or use it
synchronously inside a non-concurrent NSOperation subclass. (Please correct
me if I'm wrong!)

As Adam Maxwell said, you can use a non-concurrent operation which uses the asynchronous NSURLConnection APIs and runs the run loop itself. Handling cancel may require that you send a message from whatever thread invoked -cancel to the thread on which your operation is running, which may be non-trivial.

What messaging between threads is required? My suggestion is to periodically check [self isCancelled] and run the runloop with a timeout, and bail out if that's true. You have to do this anyway in order to support cancellation, since it doesn't stop anything on its own.


Another approach to consider is to make a concurrent operation which actually shunts its work to the main thread using - performSelectorOnMainThread:... So, NSOperationQueue would invoke - start on whichever thread it likes (you shouldn't rely on it being or not being anything in particular). -start would perform a selector on the main thread that creates the NSURLConnection and starts the download. As a consequence, it will be tied to the main thread's run loop. As data arrives, NSURLConnection will invoke your delegate methods on the main thread, too, so they shouldn't block or do long computations. (If you want to do long computations with the result of the download, you should queue up a separate operation for that once the download has completed.) Your operation class will probably want to respond to -cancel by sending -cancel to the NSURLConnection; this, too, must be shunted to the main thread.

That would probably work pretty well, assuming that generating isExecuting/isFinished KVO notifications on the main thread is okay.



Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Async NSURLConnection + Concurrent NSOperation = Not possible under Mac OS X 10.6?
      • From: Ken Thomases <email@hidden>
References: 
 >Async NSURLConnection + Concurrent NSOperation = Not possible under Mac OS X 10.6? (From: Steven Degutis <email@hidden>)
 >Re: Async NSURLConnection + Concurrent NSOperation = Not possible under Mac OS X 10.6? (From: Ken Thomases <email@hidden>)
 >Re: Async NSURLConnection + Concurrent NSOperation = Not possible under Mac OS X 10.6? (From: Steven Degutis <email@hidden>)
 >Re: Async NSURLConnection + Concurrent NSOperation = Not possible under Mac OS X 10.6? (From: Ken Thomases <email@hidden>)

  • Prev by Date: Re: KVO: when to stop observing?
  • Next by Date: Re: Async NSURLConnection + Concurrent NSOperation = Not possible under Mac OS X 10.6?
  • Previous by thread: Re: Async NSURLConnection + Concurrent NSOperation = Not possible under Mac OS X 10.6?
  • Next by thread: Re: Async NSURLConnection + Concurrent NSOperation = Not possible under Mac OS X 10.6?
  • Index(es):
    • Date
    • Thread