多线程-工作组模式

来自: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) {

扫描二维码关注公众号,回复: 2614757 查看本文章

                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)

    }

猜你喜欢

转载自www.cnblogs.com/feng9exe/p/9441238.html
今日推荐