tc39 / proposal-explicit-resource-management

ECMAScript Explicit Resource Management
https://arai-a.github.io/ecma262-compare/?pr=3000
BSD 3-Clause "New" or "Revised" License
725 stars 28 forks source link

Add `@@dispose` to iterator prototypes? #206

Closed dead-claudia closed 9 months ago

dead-claudia commented 9 months ago

Since iterators clearly are intended to use the disposer pattern, shouldn't sync iterators (like generators) also implement @@dispose/@@asyncDispose?

The implementations would just trivially delegate to return if present:

IteratorPrototype[Symbol.dispose] = function () {
    const f = this.return
    if (f != null) const {} = f.call(this)
}
AsyncIteratorPrototype[Symbol.dispose] = function () {
    const f = this.return
    if (f != null) const {} = await f.call(this)
}
rbuckton commented 9 months ago

I appreciate the feedback, but this is already included within the specification:

dead-claudia commented 9 months ago

Ah, whoops. Completely missed that!