node-async

Node.js: How to throttle a list of requests?

蓝咒 提交于 2021-01-29 01:40:38
问题 I'm writing a node.js app which needs to get some data from a list of pages from a provider: var list = [ { url: 'http://www.example.com/1' }, { url: 'http://www.example.com/2' }, ... { url: 'http://www.example.com/N' }, ]; Currently I'm using async.each, which works nicely: async.each( list, // 1st param is the array of items function(elem, callback) { // 2nd param is the function that each item is passed to request(elem.url, function (error, response, body) { if (!error && response

Node.js: How to throttle a list of requests?

◇◆丶佛笑我妖孽 提交于 2021-01-29 01:40:23
问题 I'm writing a node.js app which needs to get some data from a list of pages from a provider: var list = [ { url: 'http://www.example.com/1' }, { url: 'http://www.example.com/2' }, ... { url: 'http://www.example.com/N' }, ]; Currently I'm using async.each, which works nicely: async.each( list, // 1st param is the array of items function(elem, callback) { // 2nd param is the function that each item is passed to request(elem.url, function (error, response, body) { if (!error && response

Node.js: How to throttle a list of requests?

吃可爱长大的小学妹 提交于 2021-01-29 01:39:18
问题 I'm writing a node.js app which needs to get some data from a list of pages from a provider: var list = [ { url: 'http://www.example.com/1' }, { url: 'http://www.example.com/2' }, ... { url: 'http://www.example.com/N' }, ]; Currently I'm using async.each, which works nicely: async.each( list, // 1st param is the array of items function(elem, callback) { // 2nd param is the function that each item is passed to request(elem.url, function (error, response, body) { if (!error && response

How to grab value from promise in Nodejs

孤街醉人 提交于 2020-08-10 08:44:12
问题 Hi I am writing a nodejs code in Azure functions to capture the username saved in Azure key vault. Here is the code I have written module.exports = async function (context, req) { var msRestAzure = require('ms-rest-azure'); var KeyVault = require('azure-keyvault'); function getKeyVaultCredentials() { return msRestAzure.loginWithAppServiceMSI({ resource: 'https://vault.azure.net/' }); } function getKeyVaultSecret(credentials) { let keyVaultClient = new KeyVault.KeyVaultClient(credentials);

Choose proper async method for batch processing for max requests/sec

ε祈祈猫儿з 提交于 2020-02-09 01:55:48
问题 I need to perform a cyclic call to some external API with some delay, to prevent from 'User Rate Limit Exceeded' restriction. Google Maps Geocoding API is sensitive to 'req/sec', allowing 10 req/sec. I should make geocoding for hundreds of my contacts, and such delay is required. So, I need have a 10 async geocoding functions with post-delay in 1 sec for each. So, I collect all contacts in array, and then I loop through array in async manner. Generally, I need to have a N simultaneous threads

Why async.map function works with the native fs.stat function?

冷暖自知 提交于 2019-12-23 23:13:39
问题 async.map(['file1','file2','file3'], fs.stat, function(err, results){ // results is now an array of stats for each file }); As per documentation, the second argument is: iterator(item, callback) - A function to apply to each item in the array. Fine. The iterator is passed a callback(err, transformed) which must be called once it has completed with an error (which can be null) and a transformed item. I think that fs.stat does not conform to this and I would say that this shouldn't work. It

Node.JS async.parallel doesn't wait until all the tasks have completed

試著忘記壹切 提交于 2019-12-23 09:38:15
问题 I am using aync.parallel to run two functions in parallel. The functions request RSS feeds. Then the RSS feeds are parsed and added to my web page. But for some reason async.parallel runs the callback method without waiting until the two functions have completed The documentation says: Once the tasks have completed, the results are passed to the final callback as an array. My code. require('async').parallel([ function(callback) { fetchRss(res, bbcOpts); // Needs time to request and parse

node.js: program either exits unexpectedly or just hangs

南楼画角 提交于 2019-12-23 08:01:36
问题 I wrote a module in node.js that performs some network operation. I wrote a small script that uses this module (the variable check below). It looks like this: check(obj, function (err, results) { // ... console.log("Check completed"); }); Now here is the interesting thing. When this code executes as part of a mocha test, the test exits as expected. I see the log statement printed and the process exits. When the code is executed as a standalone node script, the log statement gets printed, but

Cannot use “map” function within async module

瘦欲@ 提交于 2019-12-19 05:08:52
问题 I am using node.js "async" module and need to use the "map" method. Basically I have an array that contains other arrays. The inner arrays contains 2 elements, a type and an image filename. var arr0 = []; var arr1 = ["type1", "image1.jpg"]; jsonArr.push(obj1); var arr2 = ["type2", "image2.jpg"]; jsonArr.push(obj2); For each inner array, I want to get the base64 encoding of the image identified by the filename and add this encoding string as the third element of the array. I'm doing something

Asynchronous http calls with nodeJS

北城以北 提交于 2019-12-19 03:41:33
问题 I would like to launch asynchronous http calls on my server node, i saw the async node module and i guess the async.parallel enables us to do that. The documented example is pretty clear, but i don't know how i could manage multiple http calls. I tried the example bellow but it doesn't even launch the http calls: var http = require('http'); var Calls = []; Calls.push(function(callback) { // First call http.get('http://127.0.0.1:3002/first' callback); }); Calls.push(function(callback) { //