alibaba / coobjc

coobjc provides coroutine support for Objective-C and Swift. We added await method、generator and actor model like C#、Javascript and Kotlin. For convenience, we added coroutine categories for some Foundation and UIKit API in cokit framework like NSFileManager, JSON, NSData, UIImage etc. We also add tuple support in coobjc.

Home Page:https://github.com/alibaba/coobjc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

COSequence 这个类移除了吗??还是说是自己封装的?

KitsGithub opened this issue · comments

commented

请问下COSequence 这个类是自己封装的吗?
内部是使用COCoroutine 生成器去实现批量下载的吗?
而且demo 中 使用

COCoroutine *co1 = xx
[co1  next]

next 方法no found

现在是 COGenerator

commented

@NianJi
在调用 COProgressPromise 为什么一直打印 test
我使用的是实例的代码

static COProgressPromise* progressDownloadFileFromUrl(NSString *url){
     COProgressPromise *promise = [COProgressPromise promise];
     [NSURLSession sharedSession].configuration.requestCachePolicy = NSURLRequestReloadIgnoringCacheData;
     NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithURL:[NSURL URLWithString:url] completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
         if (error) {
         [promise reject:error];
         }
         else{
         [promise fulfill:data];
         }
     }];
     [task resume];
     // setup progress
     [promise setupWithProgress:task.progress];
     return promise;
 }
 
 co_launch(^{
     COProgressPromise *promise = progressDownloadFileFromUrl(@"http://img17.3lian.com/d/file/201701/17/9a0d018ba683b9cbdcc5a7267b90891c.jpg");
     for(id p in promise){
         double v = [p doubleValue];
         NSLog(@"current progress: %f", (float)v);
     }
     // get the download result
     NSData *data = await(promise);
     // handle data
 });

而且运行的时候这句会报错,得注释掉才可以

NSData *data = await(promise);