Coobjc Open Sourcced: Alibaba’s Open Source Coroutine Framework for iOS Developers

Offering full coroutine support for iOS languages

The Problem of Async Programming

All About Coobjc: From Core Features to Source Code

System architecture

Operating principles

Example code

//Asynchronously loading data from the network
[NSURLSession sharedSession].configuration.requestCachePolicy = NSURLRequestReloadIgnoringCacheData;
NSURLSessionDownloadTask *task = [[NSURLSession sharedSession] downloadTaskWithURL:url completionHandler:
^(NSURL *location, NSURLResponse *response, NSError *error) {
if (error) {
return;
}

//Parsing data in child threads and generating images
dispatch_async(dispatch_get_global_queue(0, 0), ^{
NSData *data = [[NSData alloc] initWithContentsOfURL:location];
UIImage *image = [[UIImage alloc] initWithData:data];
dispatch_async(dispatch_get_main_queue(), ^{
//Dispatch to the main thread to view the image
imageView.image = image;
});
});

}];
//Main thread creates coroutine
co_launch(^{
//Asynchronous network data loading
NSData *data = await([NSURLConnection async_sendAsynchronousRequest:request response:nil error:nil]);
//Asynchronous image parsing
UIImage *image = await([UIImage async_imageWithData:data]);
//Show image
imageView.image = image;
});

Performance

In a Nutshell

Concision

Ease of use

Clarity

Performance

A final thought

— Abelson and Sussman

Alibaba Tech

First-hand & in-depth information about Alibaba's tech innovation in Artificial Intelligence, Big Data & Computer Engineering. Follow us on Facebook!