So I'm running into concurrency issues with drawing a d3 graph. My page runs perfectly with one graph, but is having trouble with multiple. Here's the relevant code in fetching the json.
json_fetching_id = "json/";
json_fetching_id += json_ids.splice(0, 1);
//here is where the d3 is grabbing the json file.
d3.json(json_fetching_id, function(error, json){
if (error) return console.warn(error);
results = results.concat(json);
callback(results); //the callback function draws the graphs.
});
console.info("Retrieving JSON file " + id);
If I have a breakpoint in the callback function, the code correctly executes with the expected display for multiple graphs, which leads me to believe it's a concurrency issue.
The above function is called in a for loop to each of the data entries I need to graph. What concerns me is that, when debugging, the debugger skips over the d3.json call, not executing the callback function. It goes through the entire for loop, not executing the callback, then executes the d3.json call after the for loop is complete -> which is where I think the concurrency issues are coming from. So my question is, is there a way to make sure to execute d3.json and its callback BEFORE going to the next item in the for loop rather than having it all execute at the end?