Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Explicit Resource Management #230

Open
RhodeHummel opened this issue Aug 29, 2023 · 0 comments
Open

Add support for Explicit Resource Management #230

RhodeHummel opened this issue Aug 29, 2023 · 0 comments

Comments

@RhodeHummel
Copy link

Is your feature request related to a problem? Please describe.
The library currently only supports disposing of objects that support the Disposable interface. However, now support for Explicit Resource Management is becoming more common and is now supported by TypeScript. It would be nice to add support for Symbol.dispose and Symbol.disposeAsync to Tsyrnge. Resource that only implement the native method of disposing of resources will not be disposed of properly by Tsyrnge and could lead to resources not being released properly.

Description
In the Explicit Resource Management proposal (which is now in Stage 3), ES will now support 2 additional symbols for disposing of explicit resources Symbol.dispose and Symbol.disposeAsync.

If the Symbol.dispose or Symbol.disposeAsync are explicitly defined we should use those functions. However, as a fallback we should continue to support the legacy Dispose(): Promise<void> | void interface for legacy code.

Alternate solutions
One alternative solution is to define the dispose function twice or more depending on your use case:

class TestClass implement Disposable {
  dispose(): Promise<void> {
     return this[Symbol.disposeAsync]();
  }
  
  [Symbol.disposeAsync]() {
    // do something here
  }
}

Additional context
Sync Proposal on github (Stage 3)
Async Proposal on github (Stage 3)
TypeScript support (TypeScript 5.2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants