Answer the question
In order to leave comments, you need to log in
How to send 10000 requests via setTimeout in Node.JS with adequate memory consumption?
There is a tabular service Airtable (a la Excel), with the ability to write rows to a table via the API. You need to roll into this service line by line 10,000 lines from the Data collection . There are API limits of 10 requests/sec. I do this placement via a view construct (setTimeout/setInterval):
Data.forEach(function(item,index){
setTimeout(function(){
API.sendData(item);
});
});
var Airtable = require('airtable');
var app = new Airtable({ apiKey: 'YOUR_API_KEY' }).app('appMzaconT6Iw9A3g');
app('Categories').create({
"Category name": "Social Innovation",
"Number of Orgs.": " 59",
"CatID": "bf5c955e6f68da36e5021d3962c28325",
"Last update": "2015-03-11T09:08:44.000Z"
}, function(err, records, newOffset) {
if (err) { console.log(err); return; }
records.forEach(function(record) {
console.log(record);
});
});
{
"id": "rec00GC0bR7Eh1bGv",
"fields": {
"Category name": "Social Innovation",
"Number of Orgs.": " 59",
"CatID": "bf5c955e6f68da36e5021d3962c28325",
"Last update": "2015-03-11T09:08:44.000Z"
}
}
Answer the question
In order to leave comments, you need to log in
I would do something like this:
var l = Data.length;
var n = 0;
function send() {
API.sendData(Data[n]);
n++;
if (n < l) {
setTimeout(send, 100);
}
}
send();
var i = 0;
var data = [];
function foo() {
if (i == data.length)
return;
// send one item to airtable
i++;
setTimeout(foo, 1000);
}
I think it's most logical to use async
async.eachLimit(records, 8, function(record, async_cb) {
/// your code
async_cb();
}, function() {
console.log('done!');
});
I know this is an old question, but I think this is the easier way.
function sleep(time) {
return new Promise((resolve, reject) => {
setTimeout(resolve, time)
})
}
async function cycle() {
const timeToSleep = 1000
console.log('start')
await sleep(timeToSleep)
for (const value of [0,1,2,3,4,5,6]) {
console.log(value)
await sleep(timeToSleep)
}
console.log('stop')
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question