Skip to content

Should an await using for sync dispose Await the return value or just Await undefined #179

@rbuckton

Description

@rbuckton

While we intend to maintain the consensus that an evaluated await using will always imply an implicit Await at the end of the block, it was suggested that the return value of a synchronous [Symbol.dispose]() method shouldn't itself be Await-ed, even if that method returns a Promise so as to remain consistent with the synchronous using statement.

The following is are examples of the current behavior and the suggested behavior:

Current behavior

{
  using x = { [Symbol.dispose]() { return Promise.reject(new Error("x")); } };

} // return value ignored, does not throw on block exit

{
  await using y = { [Symbol.dispose]() { return Promise.reject(new Error("y")); } };

} // implicit `await` for return value, throws Error("y") on block exit

Suggested behavior

{
  using x = { [Symbol.dispose]() { return Promise.reject(new Error("x")); } };

} // return value ignored, does not throw on block exit

{
  await using y = { [Symbol.dispose]() { return Promise.reject(new Error("y")); } };

} // implicit `await undefined`, return value ignored, does not throw on block exit

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