From: Jay Freeman (saurik) Date: Tue, 24 Oct 2017 06:36:12 +0000 (-0700) Subject: Provide an API that can be used by weak sets/maps. X-Git-Tag: v0.9.2~4 X-Git-Url: https://git.saurik.com/logizomai.git/commitdiff_plain/d822c88a83e3d82ee6d99935ff78f196823d5781 Provide an API that can be used by weak sets/maps. --- diff --git a/lib/index.ts b/lib/index.ts index 881b0fe..e2f7022 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -21,9 +21,11 @@ export abstract class Resource { private retainers: number; + public finalizes: Array<() => void>; constructor() { this.retainers = 0; + this.finalizes = []; } public retain(): void { @@ -40,6 +42,8 @@ export abstract class Resource { if (prototype.hasOwnProperty("@resource")) for (const property of (prototype as any)["@resource"] as string[]) (this as any)[property] = null; + for (const finalizes of this.finalizes) + finalizes(); } }