From d822c88a83e3d82ee6d99935ff78f196823d5781 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Mon, 23 Oct 2017 23:36:12 -0700 Subject: [PATCH] Provide an API that can be used by weak sets/maps. --- lib/index.ts | 4 ++++ 1 file changed, 4 insertions(+) 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(); } } -- 2.47.2