UNPKG

@hazae41/box

Version:

Rust-like Box and similar objects for TypeScript

49 lines (45 loc) 1.03 kB
'use strict'; var index$1 = require('../deferred/index.cjs'); var index = require('../void/index.cjs'); class Clone { value; clean; #count = 1; constructor(value, clean) { this.value = value; this.clean = clean; } static void() { return new Clone(undefined, new index.Void()); } static wrap(value) { return new Clone(value, value); } static from(value) { return new Clone(value.get(), value); } static with(value, clean) { return new Clone(value, new index$1.Deferred(() => clean(value))); } [Symbol.dispose]() { this.#count--; if (this.#count > 0) return; this.clean[Symbol.dispose](); } async [Symbol.asyncDispose]() { this[Symbol.dispose](); } get count() { return this.#count; } get() { return this.value; } clone() { this.#count++; return this; } } exports.Clone = Clone; //# sourceMappingURL=index.cjs.map