Just use dispatch_group_wait and dispatch_group_notify normally.
You can also use dispatch_barrier_sync / dispatch_barrier_async to use the operation after receiving all responses as a barrier block. Then this block will wait for all network requests to complete before executing.
In Java, you can use the future api of the concurrent package to implement separate requests from multiple threads, and then process the results after all responses.
Someone said NSOperation, but I won’t say it.
But I prefer GCD. This problem can be solved using barrier:
Actually, I prefer RAC, but RAC is a heavy-duty framework after all, and not many companies use it
Use RxAndroid. A .zip method is all it takes. .
A better way to use NSOperation is because of the addDependecy method~
For javascript:
https://github.com/caolan/async
It’s very convenient to handle asynchronous parallelism and serialization
Use jQuery’s Promise, or other libraries’ Promise implementation :)
Learn from the map reduce method, which is similar to the idea of merge sort
Just use dispatch_group_wait and dispatch_group_notify normally.
You can also use dispatch_barrier_sync / dispatch_barrier_async to use the operation after receiving all responses as a barrier block. Then this block will wait for all network requests to complete before executing.
I don’t know whether you are asking about Android or iOS. If it is Android, use CountDownLatch to control threads
In Java, you can use the future api of the concurrent package to implement separate requests from multiple threads, and then process the results after all responses.
for iOS
Create a serial queue for processing. Does not affect external concurrent requests.
How to implement it in JS?