@nestia/core
Version:
Super-fast validation decorators of NestJS
21 lines (17 loc) • 356 B
text/typescript
/**
* @internal
*/
export class Singleton<T> {
private value_: T | object;
public constructor(private readonly closure_: () => T) {
this.value_ = NOT_MOUNTED_YET;
}
public get(): T {
if (this.value_ === NOT_MOUNTED_YET) this.value_ = this.closure_();
return this.value_ as T;
}
}
/**
* @internal
*/
const NOT_MOUNTED_YET = {};