How can I do things when two asynchronous requests are finished ?
两个异步请求完成后,我该怎么做?
perform the asynchronous initRequest
and asynchronous refreshHeader
, they finished after I perform the requestEnd
method.
执行异步initRequest和异步refreshHeader,它们在我执行requestEnd方法后完成。
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self initRequest];
[self requestEnd];
}
- (void)initRequest{
[GBCompanyRequest requestWithSuccess:^(EvaluationAverage *evaluationAverage) {
} failure:^(NSString *message) {
}];
[self refreshHeader];
}
- (void)refreshHeader{
[GBCompanyEvaluationRequest requestWithSuccess:^(EvaluationAverage *evaluationAverage) {
} failure:^(NSString *message) {
}];
}
- (void)requestEnd{
NSLog(@"How can I do things when two asynchronous requests are finished");
}
@end
1 个解决方案
#1
1
My suggestion is use dispatch_group_t
我的建议是使用dispatch_group_t
dispatch_group_t : Generally use for call/execute group of synchronously or asynchronously method/block and it will notify you after all the method/block execution are done.
dispatch_group_t:通常用于同步或异步方法/块的调用/执行组,它将在完成所有方法/块执行后通知您。
For more information about how to use, you can read this Q/A.
有关如何使用的更多信息,您可以阅读此Q / A.
Waiting until two async blocks are executed before starting another block
在启动另一个块之前等待直到执行两个异步块
#1
1
My suggestion is use dispatch_group_t
我的建议是使用dispatch_group_t
dispatch_group_t : Generally use for call/execute group of synchronously or asynchronously method/block and it will notify you after all the method/block execution are done.
dispatch_group_t:通常用于同步或异步方法/块的调用/执行组,它将在完成所有方法/块执行后通知您。
For more information about how to use, you can read this Q/A.
有关如何使用的更多信息,您可以阅读此Q / A.
Waiting until two async blocks are executed before starting another block
在启动另一个块之前等待直到执行两个异步块