1

I am executing NSURLSession requests to fetch JSON objects from a cloud service, most of these are calls are synch and have no dependencies but in one instance I have a dependency to take into account, I have to ensure that 2 NSURLSessions are performed in order and that the first one is finished before the second one starts so I created a queue as follows

jsonQ = dispatch_queue_create("com.jongel.jsonQ", NULL);

And then I dispatch my jobs like this

  dispatch_async(jsonQ, ^{
  [helperFunctions synchOh];
  [helperfunctions synchOrp];
  });

Will doing it this way wait for the synchOh NSURLSession asynch call to return before it launches the synchOrp or will it dispatch the synchOrp call as soon as the synchOh call is dispatched?

Does it matter if I change the dispatch_asynch to dispatch_synch?

Matt Douhan
  • 2,053
  • 1
  • 21
  • 40
  • An asynchronous task will not block a serial dispatch queue. You need to use a dispatch group or dispatch semaphore or even just call the second operation from the completion block of the first – Paulw11 Apr 17 '17 at 03:31
  • I guess I am back to using NSNotificationCenter because I HAVE to know when the download is finished because once finished I am displaying that data to the user. I don't see any other way? – Matt Douhan Apr 17 '17 at 04:12
  • Well, you could use a `DispatchGroup` with `notify` or ` DispatchSemaphore` to block the serial dispatch queue until the first task is complete, as I said. – Paulw11 Apr 17 '17 at 04:14
  • will google to see what I can find :) thanks – Matt Douhan Apr 17 '17 at 04:15

0 Answers0