I have a little problem with async functions (inside functionSync1 there is an async funcion). I have this code:
main() {
functionSync1();
functionSync2();
}
functionSync1() {
console.log('start');
let promise =
Promise.resolve(this.localStorage.getItem('myItem').toPromise());
promise.then((val) => console.log(val));
}
functionSync2() {
console.log('end');
}
For some reasons I can't modify code of main(), so I would like to modify functionSync1() in order to wait the end of the function until console.log(val) is executed.
Now console.log('end') is executed before console.log(val), so the output is:
start
end
myItemValue
I need this:
start
myItemValue
end
Any ideas?
main, it's not possible.