如果我同时调用 [[RKClient sharedClient] get@“foo.xml” 会发生什么? delegate:self] 在两个 UIViewController 中?
如果我在两个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您查看
get:delegate:
的 RKClient 实现,它只是执行此操作,而
load:method:params:delegate:
的实现是它不使用任何 RKClient状态/共享数据,这样您就不会看到问题。 get:delegate: 方法本身是异步的,所以无论如何这些东西都会在后台发生。
If you have a look at the RKClient implementation for
get:delegate:
it simply does thisand the implementation for
load:method:params:delegate:
isIt'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.
我猜测这两个不同的调用将在两个不同的线程上进行。话虽如此,应该不会出现任何问题,系统应该能够理清该过程,但我不确定是否会返回“第一个”。
因此总而言之,只要
[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