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

Suggestion: add using fields to classes that are auto-disposed on @@dispose #250

Open
dead-claudia opened this issue Dec 23, 2024 · 0 comments

Comments

@dead-claudia
Copy link

dead-claudia commented Dec 23, 2024

The idea is that this...

class C {
    using a = foo();
    using #b = bar();
    await using c = baz();
    await using #d = thing();
}

...is sugar for (roughly) this:

class C {
    a = foo();
    #b = bar();
    c = baz();
    #d = thing();

    [Symbol.dispose]() {
        try {
            this.a[Symbol.dispose]()
        } finally {
            this.#b[Symbol.dispose]()
        }
    }

    async [Symbol.asyncDispose]() {
        try {
            await this.c[Symbol.asyncDispose]()
        } finally {
            await this.#d[Symbol.asyncDispose]()
        }
    }
}

It'd make collections of named disposable things a lot easier to work with.

Obviously intended as a follow-on proposal, so feel free to label accordingly.

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

No branches or pull requests

1 participant