I am having trouble constructing a chain of promises. So far I just have a function calling a promise and I don't think it's working correctly.
My first function:
function checkThingIsEnabled() {
var thingIsEnabled = false;
myProvider.onReady().then(
function() {
var thing = myProvider.getThing("name" );
thingIsEnabled = thing.isEnabled();
return thingIsEnabled;
}
)
}
So this is the first promise, I'm intending the result to be returned, so I can use it in another promise:
this.callStuff = function(promise) {
promise.then(
function() {
callAnotherFunction(
checkThingIsEnabled() ? "foo" : "bar" // calling my other promise function here
);
return callback({ success: true, error: "" });
},
function(error) {
callAnotherFunction(
checkThingIsEnabled() ? "foo" : "bar" // and also here
);
callback({ success: false, error: msg });
}.bind(this)
);
};
What is the best way to do this? I need to retain the success/error function but also need to wait for the result from checkThingIsEnabled() before I call the next part of the promise