问题
What will be if I calls simultaneously [[RKClient sharedClient] get@"foo.xml" delegate:self] in two UIViewControllers? Do I have any problems?
viewController_A
{
[[RKClient sharedClient] get:@"foo.xml" delegate:self];
}
viewController_B
{
[[RKClient sharedClient] get:@"foo.xml" delegate:self];
}
回答1:
If you have a look at the RKClient implementation for get:delegate:
it simply does this
- (RKRequest *)get:(NSString *)resourcePath delegate:(id)delegate {
return [self load:resourcePath method:RKRequestMethodGET params:nil delegate:delegate];
}
and the implementation for load:method:params:delegate:
is
- (RKRequest *)load:(NSString *)resourcePath method:(RKRequestMethod)method params:(NSObject<RKRequestSerializable> *)params delegate:(id)delegate {
NSURL* resourcePathURL = nil;
if (method == RKRequestMethodGET) {
resourcePathURL = [self URLForResourcePath:resourcePath queryParams:(NSDictionary*)params];
} else {
resourcePathURL = [self URLForResourcePath:resourcePath];
}
RKRequest *request = [[RKRequest alloc] initWithURL:resourcePathURL delegate:delegate];
[self setupRequest:request];
[request autorelease];
request.method = method;
if (method != RKRequestMethodGET) {
request.params = params;
}
[request send];
return request;
}
It's not using any RKClient state / shared data so you won't see a problem. The method get:delegate: is asynchronous itself so this stuff will happen in the background anyway.
回答2:
I'm guessing that the two different calls would be on two different threads. With this being said no problems should occur, the system should be able to sort out the process, however I am not sure would return 'first'.
So in conclusion as long as the object at [RKClient sharedClient]
is thread safe (which most objects seem to be unless stated otherwise) no problems should be found
来源:https://stackoverflow.com/questions/8193089/what-will-be-if-i-call-simultaneously-rkclient-sharedclient-getfoo-xml-del