I'm looping through a .csv and it works.
The problem is that i need to slow down my Loop, because the server (later in my code) has a request limit. I tried delay()-functions like this, but they just slowed everything down. So I decided to us a localHost to slow the URL itself down - which works.
The problem: It is not one "data"going through the loop/ getting delayed/ goes on etc.
Much "data" goes through the loop at the same time - so I slow them all down at once and still reach the serverlimit.
Question 1: is there an easy way to delay(), or to say the loop that only one "data" can pass at once?
Question2: If not: I thought about limiting the loop to .csv-line 1 To put it in another loop that repeats line by line - I could not figure out how to code this - i'm new to P5 and new to Code
My Code
function gotData(data) {
var route = data.features;
for (var j = 0; j <= 1; j++ ) {
var citydata = Städte[j].split(/,/);
var lon = citydata[3];
var lat = citydata[2];
loadJSON('http://localhost:4567/2000/https://api.openrouteservice.org/directions?api_key='+ Key +'&coordinates=' +
lon + ',' + lat + '|11.789879,50.1905748&profile=' + profile + '&preference=' + preference + '&format=geojson', getData);
beginShape();
for (var i = 0; i < route[0].geometry.coordinates.length; i=i+500) {
var x = route[0].geometry.coordinates[i][0];
var y = route[0].geometry.coordinates[i][1];
noFill();
vertex(x*100-200,-y*100+6000);
}
endShape();
}
}
So I want the for "j" to loop through the hole .csv j<Städte.length
.
But then i reach my request limit.
In fact I need to ask for one Line of the .csv / delay it / send it and so on
How can i create a 2sec break after every line in my .csv?