Noob question. I clearly don't understand promises :-(. I have read extensively but I just cannot seem to get the 789 I originally set. So I have a basic piece of JavaScript that looks as follows:
<script type="text/javascript">
async function WhatIsBrand() {
let crGbApp = new OzCruisingPresentationConsumer.JavaScript.CrGbApp();
crGbApp.SearchParameterDataManager.Data.SetBrand(789);
let brand = await crGbApp.SearchParameterDataManager.Data.GetBrand();
//console.log(brand.result);
console.log('-- brand --');
console.log(brand);
console.log('-- /brand --');
console.log('-- brand.result --');
console.log(brand.result);
console.log('/brand.result');
return brand;
}
let brand2 = WhatIsBrand();
console.log('******');
console.log(brand2);
console.log('******');
console.log('######');
console.log(brand2.result);
console.log('######');
console.log('@@@@@@@@@@@@');
brand2.then(
bogus => {
console.log('2222---@@@@@@@@@@@@');
console.log(bogus);
console.log(bogus.result);
console.log('/2222---@@@@@@@@@@@@');
})
.catch(err => console.error(err));
console.log('@@@@@@@@@@@@');
</script>
Now in my web console I see as per the attached image:
EDIT1: @Phil, @CertainPerformance - Debugger will tell you the same thing:
and the promise is still pending and I get nothing back:
/EDIT1: @Phil
EDIT2: @CertainPerformance
- Added 2222---@@@@@@@@@@@@
inside the then()
- I am still back to bogus.result
being null even though bogus
contains the value I want for result which is 789:
/EDIT2: @CertainPerformance
So the value I want is there as somehow the console is completing the promise, I just cannot seem to do it in my own code.
So brand2 has a pending promise (yellow) which I need to get to completed. However I cannot seem to resolve the promise with either brand2.then()
or Promise.resolve(brand2)
as they both return errors.
So what do I "need to do" to brand2 so that I can get the value of result which is 789
instead if undefined (green)? Happy if that also means a simplification of WhatIsBrand().