-
Notifications
You must be signed in to change notification settings - Fork 34
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
Should an await using
for sync dispose Await the return value or just Await undefined
#179
Comments
It says |
@ljharb if the resource implements The precedent here is Whether to adopt that precedent or not is the question. It really begs the question of why a sync resource might return a promise from its |
I agree that would be strange, but I don't see a strong argument to deviate from precedent. If I await a non-promise object it's still awaited. |
|
I agree that it should not await, as I suggested in tc39/proposal-async-explicit-resource-management#17. Conceptually, the default implementation of [@@asyncDispose]() {
this[@@dispose]();
} and not [@@asyncDispose]() {
return this[@@dispose]();
} given that there is no expected return value. |
My expectation would be to not await: const o = {
[Symbol.asyncIterator]() {
return async function* () {
for(let i = 0; i < 10; i++) yield i;
}();
}
}
let breaker = 0;
for await (const item of o) {
console.log(item);
if(breaker++>100) break;
} This logs 0..9 but: const o = {
[Symbol.iterator]() {
return async function* () {
for(let i = 0; i < 10; i++) yield i;
}();
}
}
let breaker = 0;
for await (const item of o) {
console.log(item);
if(breaker++>100) break;
} This logs undefined 100 times. It would be weird for |
While we intend to maintain the consensus that an evaluated
await using
will always imply an implicitAwait
at the end of the block, it was suggested that the return value of a synchronous[Symbol.dispose]()
method shouldn't itself beAwait
-ed, even if that method returns aPromise
so as to remain consistent with the synchronoususing
statement.The following is are examples of the current behavior and the suggested behavior:
Current behavior
Suggested behavior
The text was updated successfully, but these errors were encountered: