How can I wait for d3.json
to fill my array saved_data
before my function callback
is executed?
I'm using saved_data
if it is not empty. Otherwise I'm requesting new data and saving it in the saved_data
variable:
if (saved_data.length > 0) {
callback(null, parse(variable, saved_data));
}
else {
// -------------- Begin Request New Data ------------------
d3.json(" ... ",
function(data) {
if (!data) return callback(new Error("unable to load data"));
saved_data = data;
});
// how to wait on d3.json? before the call back?
callback(null, parse(variable, saved_data));
}