]> git.saurik.com Git - logizomai.git/commitdiff
Provide an API that can be used by weak sets/maps.
authorJay Freeman (saurik) <saurik@saurik.com>
Tue, 24 Oct 2017 06:36:12 +0000 (23:36 -0700)
committerJay Freeman (saurik) <saurik@saurik.com>
Tue, 24 Oct 2017 06:36:12 +0000 (23:36 -0700)
lib/index.ts

index 881b0fe3319548cf0510e2b06610b1d4248bdad6..e2f70228a630e2bdf62ba3069e2f9fbfc590ff28 100644 (file)
 
 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();
     }
 }