Skip to content

xubaiwang/rc-dispose

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rc-dispose

JSR NPM

Reference counted explicit resource management in TypeScript.

Usage

import { rc } from "@xubaiwang/rc-dispose";

// foo is a disposable object
const foo = {
  [Symbol.dispose]() {
    console.log("this is disposed");
  }
}

// wrap it in rc
const rcFoo = rc(foo, { count: 2 });

// now foo need two using to dispose
using foo1 = rcFoo;
using foo2 = rcFoo;

Comparison with other approaches

  • FinalizationRegistry: not guranteed to be called
  • ordinary using: cannot span across scopes

Ceveats

  • identity from ownership to refcount is not guranteed (c.f. Rust Rc)
  • all known ceveats from Proxy

About

Reference counted explicit resource management in TypeScript.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published