博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
多线程-工作组模式
阅读量:7128 次
发布时间:2019-06-28

本文共 749 字,大约阅读时间需要 2 分钟。

来自:https://github.com/onevcat/Kingfisher

 

任务计数模式

 

    func testDownloadMultipleImages() {

        let expectation = self.expectation(description: "wait for all downloading finish")

        

        let group = DispatchGroup()

        

        for URLString in testKeys {

            if let url = URL(string: URLString) {

                group.enter()

                _ = stubRequest("GET", URLString).andReturn(200)?.withBody(testImageData)

                downloader.downloadImage(with: url, options: nil, progressBlock: { (receivedSize, totalSize) -> Void in

                    

                }, completionHandler: { (image, error, imageURL, data) -> Void in

                    XCTAssert(image != nil, "Download should be able to finished for URL: \(String(describing: imageURL)).")

                    group.leave()

                })

            }

        }

        

        group.notify(queue: .main, execute: expectation.fulfill)

        waitForExpectations(timeout: 5, handler: nil)

    }

转载地址:http://yehel.baihongyu.com/

你可能感兴趣的文章
linux下MySQL 5.6源码安装
查看>>
matlab三维画图
查看>>
安卓窗口动画修改制作心得
查看>>
CocoaPods的install和update卡在“Anylyzing dependencies”的问题解决方式[效率]
查看>>
【原】为DevExpress的ChartControl添加Y轴控制 和 GridControl中指定列添加超级链接
查看>>
监听手机录音
查看>>
AsyncTask的用法
查看>>
Unity3d Shader
查看>>
Web--CSS控制页面(link与import方式区别)
查看>>
Swagger-UI 基于REST的API测试/文档类插件
查看>>
git squash 和 git rebase
查看>>
使用Cyclone IV控制DDR2
查看>>
[Spring MVC] - 地址路由使用(一)
查看>>
线程互斥与析构函数中mutex的销毁
查看>>
[Bhatia.Matrix Analysis.Solutions to Exercises and Problems]ExI.2.7
查看>>
复习下C 链表操作(单向链表)
查看>>
栈结构的经典算法题
查看>>
Contoso 大学 - 7 – 处理并发
查看>>
好命的姑娘?命运取决于你现在在干什么!
查看>>
atitit.GUI图片非规则按钮跟动态图片切换的实现模式总结java .net c# c++ web html js...
查看>>