UNPKG

@hazae41/box

Version:

Rust-like Box and similar objects for TypeScript

64 lines (62 loc) 1.18 kB
/** * A mutable reference */ class Slot { value; /** * A mutable reference * @param value */ constructor(value) { this.value = value; } [Symbol.dispose]() { this.value[Symbol.dispose](); } async [Symbol.asyncDispose]() { this[Symbol.dispose](); } static create(value) { return new Slot(value); } get() { return this.value; } set(value) { this.value = value; } getAndSet(value) { const old = this.value; this.value = value; return old; } } class AsyncSlot { value; /** * A mutable reference * @param value */ constructor(value) { this.value = value; } async [Symbol.asyncDispose]() { await this.value[Symbol.asyncDispose](); } static create(value) { return new AsyncSlot(value); } get() { return this.value; } set(value) { this.value = value; } getAndSet(value) { const old = this.value; this.value = value; return old; } } export { AsyncSlot, Slot }; //# sourceMappingURL=index.mjs.map