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

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

Open
nicolo-ribaudo opened this issue May 19, 2023 · 1 comment
Open

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

nicolo-ribaudo opened this issue May 19, 2023 · 1 comment

Comments

@nicolo-ribaudo
Copy link
Member

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.

@nicolo-ribaudo
Copy link
Member Author

The solution is probably to wrap the @@dispose method in another function to make sure that its return value is ignored.

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

No branches or pull requests

1 participant