I have the below Promise:
function checkDetail() {
return foo.onReady().then(() => foo.myThing("bar").isActive())
}
I need to use the result from this Promise as an argument to pass in an anonymous function, and that function is itself inside a Promise.
function attemptActivate() {
promise.then(
function() {
function activateSuccessfully(checkDetail() ? "foo" : null) {
//....
};
return callback({ success: true, error: "" });
},
function(error) {
function activateUnsuccessfully(checkDetail() ? "bar" : null) {
//....
};
callback({ success: false, error: "error" });
}
)
}
I understand I could normally chain promises together using successive instances of .then(), but in the case above they are two different promises so I don't believe that I chain them directly?
Currently the argument passed to my function is always the positive ("foo" or "bar") because the ternary validates the Promise checkDetail() as true.
How can I chain the promises so that the result of checkDetail() is awaited on before the rest of the other Promise continues, and how can I get it to return the value and pass that inside the Promise?