在React Native中并行获取请求 [英] Parallel fetch requests in react native

查看:177
本文介绍了在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];

更多信息: https://developer.apple. com/documentation/foundation/nsurlsessionconfiguration/1407597-httpmaximumconnectionsperhost?language = objc

这篇关于在React Native中并行获取请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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