@trifrost/core
Version:
Blazingly fast, runtime-agnostic server framework for modern edge and node environments
31 lines (30 loc) • 673 B
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Lazy = void 0;
class Lazy {
#val = null;
#fn = null;
constructor(val) {
if (typeof val === 'function') {
this.#fn = val;
}
else if (val) {
this.#val = val;
}
}
get resolved() {
return this.#val;
}
resolve(opts) {
if (this.#val)
return this.#val;
if (!this.#fn)
throw new Error('Lazy@resolve: No initializer provided');
this.#val = this.#fn(opts);
return this.#val;
}
clear() {
this.#val = null;
}
}
exports.Lazy = Lazy;