I have a function which needs to be async (because of await sleep()
) and I want it to return a String not a Promise by calling it from another non-async function.
async function _getString() {
await sleep(50);
return "Hello World";
}
// BY DOING THAT:
function getString() {
return _getString().GET_PROMISE_VALUE();
}
I know currently of two possibility to get the value of the Promise:
await getString()
getString().then((result) => {anotherVariable = result});
The problem is:
- I want to pause code execution where the function is called, because then
anotherVariable
might get used before it gets assigned toresult
- I don't want to use await because I would need another async function
Is there a way to make getString() wait until _getString() finished and then get the result?