RestKit 0.2x simultaneous RKManagedObjectRequestOperation

吃可爱长大的小学妹 提交于 2020-01-25 11:32:07

问题


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) send GET request n. 1, send GET request n. 2, send GET request n. 3

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

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

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

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

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

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

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

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

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

2) start mapping response 1

3) start mapping response 2

4) mapping response 1 ends

5) mapping response 2 ends

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.

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) ??

Am I crazy? :D


回答1:


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. Don't run the requests concurrently
  2. Have all of the stub objects created up front and then the responses populate and relate them

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.



来源:https://stackoverflow.com/questions/22880223/restkit-0-2x-simultaneous-rkmanagedobjectrequestoperation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!