RestKit 0.2x同时RKManagedObjectRequestOperation [英] RestKit 0.2x simultaneous RKManagedObjectRequestOperation

查看:253
本文介绍了RestKit 0.2x同时RKManagedObjectRequestOperation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在RestKit 0.10.3中使用委托方法我能够发送同时的GET请求,即使每个的映射是顺序执行。我有GET请求,需要这么多时间来接收响应,所以我想同时发送所有请求,但尊重映射中的顺序(我有关系穿越三个请求)。我需要:

In RestKit 0.10.3 using delegate methods I was able to send simultaneous GET requests, even if mapping of each one was executed sequentially. I have GET requests which need so much time to receive a response, so I would like to send all requests simultaneously but respect an order in mapping (I have relationships crossing the three requests). What I need:


1)发送GET请求n。 1,发送GET请求n。 2,发送GET请求n。 3

1) send GET request n. 1, send GET request n. 2, send GET request n. 3

2)在收到响应1时开始映射请求1

2) start mapping of request 1 as soon as response 1 is received

响应1完成,等待响应2并映射
(或者如果已经接收到则开始映射)

3) when mapping of response 1 did finish, wait for response 2 and map (or just start mapping if already received)

4)当响应2的映射完成时,等待对于响应3和映射
(或者只是开始映射,如果已经接收)

4) when mapping of response 2 did finish, wait for response 3 and map (or just start mapping if already received)

似乎发生了什么(如果operationQueue在objectManeger未设置为1):

What seems to happen (if operationQueue on objectManeger is NOT set to 1):


1)发送GET请求n。 1,发送GET请求n。 2,发送GET请求n。 3

1) send GET request n. 1, send GET request n. 2, send GET request n. 3

2)在收到回应后即可映射回应

2) map a response as soon as is received and the previous mapping has finished

问题1:是否可以尊重映射中的订单?

Question 1: is it possible to respect an order in mapping?

问题2:可以同时发生更多响应(点2)的映射吗?换句话说,这是可能的:

Question 2: can the mapping of more responses (point 2) occur simultaneously? In other words, is this possibile:


1)发送GET请求n。 1,发送GET请求n。 2

1) send GET request n. 1, send GET request n. 2

2)开始映射回应1

2) start mapping response 1

3)开始映射回应2

3) start mapping response 2

4)映射响应1结束

5)映射响应2结束

如果这是不可能的,我会有一个半的解决方案:enqueue每个请求在willMapDeserializedResponseBlock。请求不会同时发送,但至少我将能够在上一次映射之前发送每个请求。

If this is not possible, I would have a "half" solution: enqueue each request in willMapDeserializedResponseBlock. The requests will not be send simultaneously, but at least I will be able to send each request before the previous mapping.

问题3: if我复制了在交叉关系两侧的entityMappings的addConnectionForRelationship,三个映射应该同时执行,顺序应该不再重要。这是可能的,而不创建一些邪恶的行为(重复的对象,孤立的对象,缺少关系,性能低下)。

Question 3: if I duplicate the "addConnectionForRelationship" of entityMappings on both sides of crossed relationship, the three mappings should be executed simultaneously and the order should not be important anymore. Is this possible without creating some evil behavior (duplicate objects, orphaned objects, missing relationships, low performance) ??

我疯了吗?
:D

Am I crazy? :D

推荐答案

如果您在数据库中没有现有对象,那么在后台同时运行多个操作将会导致问题,因为您将尝试在不同线程的多个上下文中连接或阻止重复。

If you don't have existing objects in the database then concurrently running multiple operations in the background will cause issues because you will be trying to connect or prevent duplicates across multiple contexts in different threads.

两种常见的解决方案是:

The 2 general solutions are:


  1. 不要同时运行请求

  2. 先创建所有存根对象,然后填充响应, li>
  1. Don't run the requests concurrently
  2. Have all of the stub objects created up front and then the responses populate and relate them

如果您需要明确命令,那么您应该使用AFNetworking同时执行下载,然后对响应数据使用RestKit映射操作,指定它们之间的依赖关系。

If you need the order to be explicit then you should use AFNetworking to execute the downloads concurrently and then use RestKit mapping operations with the response data and specify dependencies between them.

这篇关于RestKit 0.2x同时RKManagedObjectRequestOperation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆