Skip to content

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

Open
@dead-claudia

Description

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.

Activity

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

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions