dispatch_semaphore_create(long value); // 创建信号量 dispatch_semaphore_signal(dispatch_semaphore_t deem); // 发送信号量 dispatch_semaphore_wait(dispatch_semaphore_t dsema, dispatch_time_t timeout); // 等待信号量
MJWeakSelf dispatch_semaphore_t sem = dispatch_semaphore_create(0); dispatch_async(dispatch_get_global_queue(0, 0), ^{
NSDictionary *dic = @{@"roomId":self.currentRoomId};
[NetManager getAnchorInfoWithDic:dic handler:^(LKTheHostAnchorInfoModel *model, NSError *error) {
if ([model.code isEqualToString:@"success"]) {
weakSelf.anchorInfoModel = model.data;
}
dispatch_semaphore_signal(sem);
}];
});
dispatch_async(dispatch_get_global_queue(0, 0), ^{
dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
NSDictionary *dic = @{@"roomId":self.currentRoomId};
[NetManager getAnchorInfoWithDic:dic handler:^(LKTheHostAnchorInfoModel *model, NSError *error) {
if ([model.code isEqualToString:@"success"]) {
weakSelf.anchorInfoModel = model.data;
}
dispatch_semaphore_signal(sem);
}];
});
dispatch_async(dispatch_get_global_queue(0, 0), ^{
dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.dataArray = [weakSelf loadLocalData:weakSelf.anchorInfoModel queryAnchor:weakSelf.queryAnchorModel eventList:weakSelf.eventListDataModel.reserveEventList];
[weakSelf endDataRefresh];
});
});