react native 中的并行获取请求

Parallel fetch requests in react native(react native 中的并行获取请求)

本文介绍了react native 中的并行获取请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 react native 中开发一个新应用程序,我需要将 20 次获取 并行到我的 api 中.当我在电话间隙中进行开发时,我可以创建 20 个 web workers 来让 Ajax 调用并行发生.当我在 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 应用程序 中完成提取需要 1 分钟,它需要 10 秒..非常感谢您的帮助

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 中的并行获取请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:react native 中的并行获取请求

基础教程推荐