I think I got the idea of promise as it name speaks out, we can or can't have a result in return. To access the resolved value we need to call then on the promise. This is my catch.
I don't want to do anything with result, I just want to return value because it is an API function that I'm developing.
I have two promises like this:
var willWeGetConsumptions = new Promise(function(resolve, reject) {
var willWeGetPrices = new Promise(function(resolve, reject) {
and another consumer promise like this:
var finalPromise = Promise.all([willWeGetConsumptions, willWeGetPrices]).then(function(values) {
My thoughts are:
- Return from
var finalPromise = Promise.all
when done, (when resolve is called), Although I couldn't. - Set Timeout function (which I think is possible but I don't know how). It should wait for resolved value and return directly. It should be in the same scope level as declared promises, and not defined inside one of them.
All other solutions are refering to logging on finalPromise.then(function(value) { console.log(value)});
I think it is clear now that I want a returned value, without further dealing with it.
Last edit: For those who didn't understand. Obviously, I don't want to user (caller of API) to deal with a Promise object (even always I assure that is resolved).
Why last edit? because I am now aware this is a wider problem, as referred like duplicate. it's true, the question is how to return from an Async function.