在React Native中并行获取请求 [英] Parallel fetch requests in react native
问题描述
我正在react native
中开发一个新应用,我需要将20 fetches
并行添加到我的api
中.当我开发电话间隙时,可以为Ajax
调用创建20 web workers
以并行发生.当我在react native
中并行执行20 fetches
时,似乎每次提取所花的时间都比以前长.就像它有一个获取队列,它不会一起运行.
I am developing a new app in react native
and I need to make 20 fetches
to my api
in parallel. When I developed in phone gap, I could create 20 web workers
for the Ajax
calls to happen parallel. When I am executing 20 fetches
in parallel in react native
it looks like every fetch is taking longer than the one before. Like it has a queue of fetches and it won't run them together.
有什么办法解决这个问题?现在,在我的phonegap app
中,像10 secs
一样,需要完成1 minute
的提取.
帮助将不胜感激
Is there any way to solve this? Now it takes like 1 minute
to finish the fetches when in my phonegap app
it takes like 10 secs
..
Help would be much appreciated
推荐答案
在iOS中,每个主机的连接数限制为四个.您需要在NSURLSession中增加HTTPMaximumConnectionsPerHost.
The number of connections per host is limited to four in iOS. You need to increase HTTPMaximumConnectionsPerHost in NSURLSession.
测试此问题的丑陋方法是将以下行直接添加到node_modules/react-native/Libraries/Network/RCTHTTPRequestHandler.m: NSURLSessionConfiguration
The ugly way to test this is to directly add the following line to node_modules/react-native/Libraries/Network/RCTHTTPRequestHandler.m: NSURLSessionConfiguration
[configuration setHTTPMaximumConnectionsPerHost:25];
这篇关于在React Native中并行获取请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!