I'm new to asynchronous programming
function loadPlugin(plugins, callback) {
let tests = [[], [], []];
plugins.forEach((plugin) => {
f.isPlugin(plugin, (exists) => {
if (exists) {
if (!f.pluginIsLoaded(plugin)) {
tests[0].push(plugin);
f.loadPlugin(plugin);
} else {
tests[1].push(plugin);
}
} else {
tests[2].push(plugin);
}
});
console.log(tests);
});
return tests;
}
and
module.exports.isPlugin = (plugin , callback) => {
fs.access(`./plugins/${plugin}`, fs.constants.F_OK, (err) => {
callback(!err);
});
};
Inside f.isPlugin(plugin, (exists) => { }); I push plugin into the tests array and I console.log(tests) from the outer function it shows that the tests array is an array containing 3 empty arrays in it.
Is there a way I can retain the the stuff pushed inside f.isPlugin(plugin, (exists) => { }); so I can access it from the outer functions?
f.isPluginwhich is insideplugins.forEach. I want it to let it loop all and fill thetestsbefore returning it, I'm not sure how to approach it.