title: How to timeout an asynchronous method when ran synchronously
body: <p>This is essentially what I'm doing to run an asynchronous method synchronously:</p>
  
  <p>This essentially works when called once, but when called multiple times, it will eventually stay inside the while loop and never get signaled. Any ideas on how to set a timer to eventually time out after sometime?</p>
  
  <pre><code>__block SomeClass *result = nil;
  
  dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
  dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0UL);
  dispatch_async(queue, ^{
      [[SomeManager sharedInstance] someMethodWithCallback:^(id responseObject, NSError *error) {
          if (!error) {
              result = (SomeClass *)ResponseObject;
          }
  
          dispatch_semaphore_signal(semaphore);
      }];
  });
  
  // wait with a time limit
  while (dispatch_semaphore_wait(semaphore, DISPATCH_TIME_NOW)) {
      [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0]];
  }
  
  dispatch_release(semaphore);
  </code></pre>
  
  <p>Thanks</p>