zoukankan      html  css  js  c++  java
  • 多网络并发

        // 创建信号量

        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操作

                

                NSLog(@"%@--",[NSThread currentThread]);

                

            });

            

            

        });

       

    一天一章
  • 相关阅读:
    团队项目01应用场景
    团队项目冲刺第一阶段03
    团队冲刺第一阶段02
    团队冲刺第一阶段01
    基于 Scrapy-redis 的分布式爬虫详细设计
    创建CrawlSpider爬虫简要步骤
    如何将redis中的数据导入到本地MongoDB和MySQL数据库
    远程访问ubuntu下mysql的问题
    vi命令汇总
    Chrome/FireFox处理JSON的插件
  • 原文地址:https://www.cnblogs.com/hangman/p/11239169.html
Copyright © 2011-2022 走看看