I have a Typescript project with a function that is not Async. This function can’t be changed to async and this is giving me trouble to call an Async function and retrieve a value synchronously.
Is there a way I can await for my async function to evaluate before I continue the execution of the Main function? If I use the async
keyword, it forces me to make the Main function async too.
Main function looks like this:
export const sortList = (
list: Item[],
): Item[] => {
const retrieveValueSynchronously = await getMyValue();
return map(
orderBy(list, item => item.timeStamp, "desc"),
item => {
..... some more code here that uses **retrieveValueSynchronously**
}
)
};
And this is my async function:
public async getMyValue(): Promise<string> {
const { cachedMetadata } =
await this.getCachedMetadata();
return cachedMetadata;
}