I have this multiple function called checkForURLS that calls another two functions that return callbacks, how can I add to the array once both callbacks have returned and then return the array as a callback? I'm working with pure JavaScript.
function checkForURLs(uniqueURL, customURL, callback) {
var errors = [];
checkForUniqueURL(uniqueURL, function(UniqueURLCallback) {
if (UniqueURLCallback===true) {
errors.push("This unique URL is already taken, please try another.");
}
});
if (customURL.length>0) {
checkForCustomURL(customURL, function(customURLCallback) {
if (customURLCallback===true) {
errors.push("This custom URL is already taken, please try another.");
}
});
}
if (errors.length>0) {
return callback(errors);
} else {
return callback(false);
}
}
checkForURLs(urlA, urlB, function(error) { /* handle your error in the callback function */ });. Isn't that, what you want? What do you want?checkForUniqueURL()does something asynchronous and all this should be done using promises. Show all relevant code