Skip to content
Snippets Groups Projects
Commit aba3ada8 authored by michael.minelli's avatar michael.minelli
Browse files

Add LazyVal class (lazy loading of values)

parent 787234f1
No related branches found
No related tags found
No related merge requests found
class LazyVal<T> {
private val: T = null;
constructor(private valLoader: () => Promise<T>) {}
get value(): Promise<T> {
return new Promise<T>(async (resolve) => {
if (this.val === null) {
this.val = await this.valLoader();
}
resolve(this.val);
});
}
reset() {
this.val = null;
}
get isValueLoaded(): boolean {
return this.val !== null;
}
}
export default LazyVal;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment