Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You should not do IO on the main thread, your need to try to handle a run-loop is evident. Run-loops are tricky, especially since many events do not make the runloop call exit as expected <em>(Anything run on a timer for one, performing selectors just happens to be run on a timer)</em>. You could probably solve your problem by not waiting for <code>distantFuture</code>, but just for a few hundred milliseconds at a time.</p> <p>What you really want to to do is top run <code>my_connect()</code> in a background thread, and just wait for a condition. This code will be much easier to handle, look like less of a hack, and actually perform better.</p> <p>You can use an instance of <code>NSConditionLock</code> to implement the wait. It is not super obvious how to do this. But you can create a shared instance on <code>NSConditionLock</code> in the variable <code>condLock</code> like this:</p> <pre><code>condLock = [[NSConditionLock alloc] initWithCondition:0]; </code></pre> <p>And this is then how you would implement the waiting in <code>my_connect()</code>:</p> <pre><code>[condLock lockWhenCondition:1]; // Add code that needs to be thread safe here if you like. [condLock unlockWithCondition:0]; </code></pre> <p>And this is how you would signal the <code>NSConditionLock</code> that it is time to continue from you delegate method.</p> <pre><code>[condLock lock]; // More thread safe code here if you like [condLock unlockWithCondition:1]; </code></pre> <p>You could assign some constants to use instead of <code>0</code> and <code>1</code> explicitly, and have a quite nice solution.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload