• 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
NSURLConnection's scheduleInRunLoop:forMode: not working
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSURLConnection's scheduleInRunLoop:forMode: not working


  • Subject: NSURLConnection's scheduleInRunLoop:forMode: not working
  • From: Jens Alfke <email@hidden>
  • Date: Tue, 09 Aug 2011 10:36:53 -0700

I have a situation where I need to block until an already-running asynchronous NSURLConnection completes. I block by spinning a nested runloop until my delegate gets notified of completion. To avoid nasty reentrancy issues, I do the blocking in a custom runloop mode — that ensures no other actions happen on this thread while I’m waiting (timers, other NSURLConnections, etc.)

The problem is that I can’t seem to schedule the connection into my custom mode — the scheduleInRunLoop:forMode: call has no effect, even though the docs say that it’s OK to call it on an already-started connection. I can tell it has no effect because the runloop’s -runMode:beforeDate: exits immediately returning NO, which implies that there are no input sources for my custom mode. (On the other hand, -scheduleInRunLoop:forMode: works just fine if I call it before starting the connection.)

The full source code is at <https://github.com/couchbaselabs/CouchCocoa/blob/master/REST/RESTOperation.m>.

The connection is started asynchronously like so:

    _connection = [[NSURLConnection alloc] initWithRequest: _request
                                                  delegate: self
                                          startImmediately: NO];
    [_connection scheduleInRunLoop: [NSRunLoop currentRunLoop] forMode: NSRunLoopCommonModes];
    [_connection start];

Here’s the bit of code (down in another method) that blocks.

    [_connection scheduleInRunLoop: [NSRunLoop currentRunLoop] forMode: kRESTObjectRunLoopMode];
    while (_connection && _state == kRESTObjectLoading) {
        if (![[NSRunLoop currentRunLoop] runMode: kRESTObjectRunLoopMode
                                      beforeDate: [NSDate distantFuture]])
                break;
    }

(I’m on Lion, 10.7.0.)

—Jens

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

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: NSURLConnection's scheduleInRunLoop:forMode: not working
      • From: Mark Pauley <email@hidden>
  • Next by Date: Re: NSURLConnection's scheduleInRunLoop:forMode: not working
  • Next by thread: Re: NSURLConnection's scheduleInRunLoop:forMode: not working
  • Index(es):
    • Date
    • Thread