Skip to content

Instantly share code, notes, and snippets.

@ddribin
Created February 15, 2010 15:41
Show Gist options
  • Save ddribin/304741 to your computer and use it in GitHub Desktop.
Save ddribin/304741 to your computer and use it in GitHub Desktop.
{
NSOperationQueue * queue = [[[NSOperationQueue alloc] init] autorelease];
NSURL * url = [NSURL URLWithString:@"http://www.example.com/"];
id<DDFuture> futureData = [queue dd_submitCallableBlock:^id (NSError **error) {
NSData * data = [NSData dataWithContentsOfURL:url options:0 error:error];
return data;
}];
// This blocks for the result
NSError * error = nil;
NSData * data = [futureData result:&error];
if (data != nil) {
NSString * string = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
NSLog(@"String:\n%@", string);
} else {
NSLog(@"Error: %@", error, [error userInfo]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment