I have an asynchronous function that is called from a synchronous function as shown below.
public syncFunction(data: Data): Value[] {
const results: Value[] = [];
// read data object and do some stuff
results.push(data.value)
// Call async function
const val = this.asyncFunction()
results.push(val);
return results;
}
public async asyncFunction(): Value {
let result = await this.anotherAsyncFunction();
// Do some stuff
return result;
}
By doing this, the type of the variable named val
it is, of course, a Promise.
What I would like to do is resolve the promise, push the value in the results
array and than return the array.
I tried to use this.asyncFunction.then()
but the return statements is executed first.
Is it possible to do something like this?
Within the project all functions are synchronous and I do not have the possibility to modify it