Skip to content

Instantly share code, notes, and snippets.

@baz
Created February 21, 2014 00:38
Show Gist options
  • Save baz/9126573 to your computer and use it in GitHub Desktop.
Save baz/9126573 to your computer and use it in GitHub Desktop.
RAC wrapping AFNetworking
- (RACSignal *)enqueueHTTPRequestWithRequest:(NSURLRequest *)request {
RACScheduler *scheduler = bee_plugin_rac_scheduler();
RACSignal *requestSignal = [[RACSignal createSignal:^(id<RACSubscriber> subscriber) {
AFHTTPRequestOperation *requestOperation = [self HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {
[subscriber sendNext:responseObject];
[subscriber sendCompleted];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[subscriber sendError:error];
}];
[self enqueueHTTPRequestOperation:requestOperation];
return [RACDisposable disposableWithBlock:^{
[requestOperation cancel];
}];
}] deliverOn:scheduler];
return [[requestSignal replayLazily] setNameWithFormat:@"-enqueueHTTPRequestWithRequest: %@", request];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment