I am currently in the process of updating my code to incorporate the latest TypeScript enhancements. We have implemented various memoization patterns, with the main goal being to ensure that services with multiple subscribers wait for one call and do not trigger multiple calls simultaneously.
Here is a snippet of the code:
private isAdmin: Promise<Boolean>;
public IsCurrentUserAdmin(): Promise<Boolean> {
if (!this.isAdmin) {
this.isAdmin = httpService.goGetTheData().then((data) => //perform actions and return Boolean);
}
return this.isAdmin;
My query is: Will using something like this achieve the same result as with the await operator since I do not have direct access to the promise object?
public IsCurrentUserAdmin(): Promise<Boolean> {
const isAdminData = await httpService.goGetTheData();
// manipulate the data to obtain the desired value
return isAdmin;
}