ios - Mulithreading: executing method calls only after finished executing other method -
i trying process method asynchronously, per requirements, once first method has completed, second method should start executing. problem first method has code runs on background thread.
i tried dispatch_semaphore_wait, didnt work either.
dispatch_queue_t queue = dispatch_get_global_queue(dispatch_queue_priority_high, 0); dispatch_group_t group = dispatch_group_create(); dispatch_group_async(group, queue, ^{ [self firstmethod]; nslog(@"firstmethod done"); }); dispatch_group_notify(group, queue, ^ { nslog(@"1st method completed"); nslog(@"2nd method starting"); [self secondmethod]; });
firstmethod runs on worker thread this
-(void)firstmethod { dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_high, 0), ^{ //processing here..... }];
what best way achieve it, cannot change definition of firstmethod provided 3rd party , changing means changing lots of existing code method being called
you can use completion block. need modify firstmethod way:
- (void)firstmethodwithoncomplete:(void (^)(void))oncomplete { dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_high, 0), ^{ //processing here..... oncomplete(); }); }
and use way:
[self firstmethodwithoncomplete:^{ [self secondmethod]; }];
Comments
Post a Comment