Skip to content
This repository was archived by the owner on Jun 20, 2023. It is now read-only.

The promise returned by @@dispose should not be awaited #17

@nicolo-ribaudo

Description

@nicolo-ribaudo

When the language uses synchronous iterators as fallbacks for asynchronous iterators (using https://tc39.es/ecma262/#sec-async-from-sync-iterator-objects), it doesn't await the promises returned by next():

let done = false;

const it = {
  [Symbol.iterator]() {
    return {
      next() {
        let p = Promise.resolve({ value: 1, done });
        p.value = 2;
        p.done = done;
        done = true;
        return p;
      }
    }
  }
}

for await (const v of it) {
  console.log(v); // logs 2; if you replace @@iterator with @@asyncIterator it logs 1.
}

As such, if when using await using there is no @@asyncDisposable and thus we use the @@disposable fallback, if it returns a promise it should not be awaited.

The proposal spec doesn't distinguish between the method store in @@asyncDisposable and the one stored in @@disposable (steps 1.a and 1.b.i of https://tc39.es/proposal-async-explicit-resource-management/#sec-getdisposemethod).

I found this inconsistency while implementing this proposal in Babel: babel/babel#15633.

Metadata

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