I prefer to use "await" command and async functions to get rid of confusions of promises,
In this case I would write an asynchronous function first,
this will be used instead of the anonymous function called under "promise.then" part of this question :
async function SubFunction(output){
// Call to database , returns a promise, like an Ajax call etc :
const response = await axios.get( GetApiHost() + '/api/some_endpoint')
// Return :
return response;
}
and then I would call this function from main function :
async function justTesting() {
const lv_result = await SubFunction(output);
return lv_result + 1;
}
Noting that I returned both main function and sub function to async functions here.
then()
call is again a promise, which wraps the value your returned.promise
. You don't show it defined anywhere and you don't return anything from yourjustTesting()
function. If you want better help, you need to describe what problem you're trying to solve rather than just showing us code that is so "off" that it doesn't even illustrate what you're really trying to do. Explain the problem you're trying to solve.