ios - Stopping an infinite while loop inside dispatch_async from another View Controller -


I that I have a NSURLConnection sendSynchronousRequest I make a simple chatroom app: vote a la Long send requests to a server. I have a stream that constantly updates while running in the background while wanting to show chat feeds for my users.

My app also allows users to change their chatrooms, from which I need another need to close and open an NSURLConnection. Related Feeds

My current implementation is as follows:

  ViewController.m // in dispatch_queue_t concurrentQueue = dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_async (concurrentQueue, ^ {while (longPollBOOL) {NSArray * MSG = [self.currentChatFeed longPoll] ;! // infinitely longPoll method dispatch_sync (dispatch_get_main_queue (), ^ {if (MSG.count = 0) // if longPoll call method Gives a non-empty array, it sticks in the message feed on the device. {{Self.messages addObject: element]; [self-completionReceivingMessage];}}}};}});  

I am trying to kill the loop by setting my name = but it is not working. That BOOL = NO is being sent by another view controller in the app. I want to guarantee that this loop has been stopped before another infinite loop is started for the other chat room.

Before I start another long voting process, I want to kill this long pole process for a given chat room.

If you want a cancelable job you can call it NSOperation s You can easily do modeling without sub-clinging:

NSBlockOperation * blockOperation = [[NSBlockOperation alloc] init]; __wec __typeof (block operation) weak block operation = block operation; [Block Operation Adaxacionball: ^ {While Cobbler Block Operation. IS canceled!) {NSARRA * MSG = [Self-Crurftafid Long Paul]; // infinite longPoll method dispatch_sync phone (, dispatch_get_main_queue () ^ {if (MSG.count & gt; 0) {for (ID elements) in {MSG [self.messages addObject: Abstract] [self finishReceivingMessage];}} }); }}]; [Add quote operation: block operation];

You need to capture the context of your operation and you can cancel it at any time.


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -