GCD实战之多个网络请求的并发
2024-08-30 05:19:08
// 创建信号量
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
// 创建全局并行
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_group_t group = dispatch_group_create();
dispatch_group_async(group, queue, ^{
// 请求一
[loginCode getUserInfoWithNick:nil andUserId:kUserId onSuc:^(id data) {
NSLog(@"yue");
dispatch_semaphore_signal(semaphore);
} andFail:^(NSError *error) {
}];
});
dispatch_group_async(group, queue, ^{
// 请求二
[CommodityViewModel getPriceTransformForIntegral:nil onSuccess:^(id data) {
NSLog(@"duihuan11");
dispatch_semaphore_signal(semaphore);
} onFailure:^(NSError *error) {
}];
});
dispatch_group_async(group, queue, ^{
// 请求三
[CommodityViewModel getPriceTransformForIntegral:nil onSuccess:^(id data) {
NSLog(@"duihuan22");
dispatch_semaphore_signal(semaphore);
} onFailure:^(NSError *error) {
}];
});
dispatch_group_notify(group, queue, ^{
// 三个请求对应三次信号等待
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
//在这里 进行请求后的方法,回到主线程
dispatch_async(dispatch_get_main_queue(), ^{
//更新UI操作
});
});
最新文章
- VS2012中丢失ArcGIS模板的解决方法
- 快速定位性能瓶颈,检查出所有资源(CPU、内存、磁盘IO等)的利用率(utilization)、饱和度(saturation)和错误(error)度量,即USE方法
- 达梦7的试用 与SQLSERVER的简单技术对比
- query语句的拼接.
- HTML-学习笔记(1)
- mybaits入门
- git 创建版本库
- JavaWeb学习计划
- dell 交换机 双链路冗余
- 【转】android资源目录---assets与res/raw区别
- 你的Jsp页面有黄×么,有黄色问号么?Multiple annotations found at this line: - Invalid location of tag (form). - No
- Android创建和使用数据库详细指南(1)
- B-JUI(Best jQuery UI) 前端框架
- 模板类的约束模板友元函数:template friend functions
- 利用ASCII码生成指定规则的字符串
- [Codeforces]852I - Dating
- JSON AST 生成MD
- Android APP性能测试笔记(二)
- HTTP Client使用总结
- Jmeter常用脚本开发之SOAP/XML-RPC Request
热门文章
- document.documentElement 和 document.body
- 怎样提高js的编程能力
- PTA --- Basic Level 1009 说反话
- Python爬虫学习==>;第二章:MongoDB环境配置
- markdown-博客编辑
- react中component存在性能问题
- 华为HCNA乱学Round 9:VRRP
- 【Linux开发】linux设备驱动归纳总结(五):4.写个简单的LED驱动
- Flash-aware Page Replacement Algorithm
- 【CSP模拟】小凯的疑惑(DP)