如果我同时调用 [[RKClient sharedClient] get@“foo.xml” 会发生什么? delegate:self] 在两个 UIViewController 中?

发布于 2024-12-17 05:46:05 字数 285 浏览 0 评论 0原文

如果我在两个 UIViewController 中同时调用 [[RKClient sharedClient] get@"foo.xml" delegate:self] 会怎样?我有什么问题吗?

viewController_A
{
[[RKClient sharedClient] get:@"foo.xml" delegate:self];
}

viewController_B
{
 [[RKClient sharedClient] get:@"foo.xml" delegate:self];
}

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];
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

记忆消瘦 2024-12-24 05:46:05

如果您查看 get:delegate: 的 RKClient 实现,它只是执行此操作

- (RKRequest *)get:(NSString *)resourcePath delegate:(id)delegate {
    return [self load:resourcePath method:RKRequestMethodGET params:nil delegate:delegate];
}

,而 load:method:params:delegate: 的实现是

- (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;
}

它不使用任何 RKClient状态/共享数据,这样您就不会看到问题。 get:delegate: 方法本身是异步的,所以无论如何这些东西都会在后台发生。

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.

青芜 2024-12-24 05:46:05

我猜测这两个不同的调用将在两个不同的线程上进行。话虽如此,应该不会出现任何问题,系统应该能够理清该过程,但我不确定是否会返回“第一个”。

因此总而言之,只要 [RKClient sharedClient] 处的对象是线程安全的(大多数对象似乎都是线程安全的,除非另有说明),就不会发现任何问题

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文