I have three tasks. task1,task2 and task3. task1 and task2 are async tasks,i.e. they do task concurrently and the time of returning finish result is unpredictable . originally, I hope task1 and task2 do at same time,and after getting result to do task3.
dispatch_group_t dispatchGroup = dispatch_group_create();
dispatch_group_async(dispatchGroup,dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//do task1 async
});
dispatch_group_async(dispatchGroup,dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//do task2 async
});
dispatch_group_notify(dispatchGroup, dispatch_get_main_queue(), ^(){
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
while (true) {
sleep(0.2); //avoid cpu timeslice fully used
//after get task1 and task2 result
// do task3
}});
I designed the structure as above,but I always get bad result,like if task2 is a url post request using afnetworking, I can't get success block involved.
anybody help me I will be appreciate.