Skip to content

Asynchronously using a synchronous disposable that returns a Promise #256

Closed
@rictic

Description

@rictic

Should a promise returned by a Symbol.dispose method be awaited by AsyncDisposableStack#use / await using?

Put another way:

{
  const stack = new AsyncDisposableStack();
  const neverResolves = Promise.withResolvers().promise;
  stack.use({[Symbol.dispose]() { return neverResolves }});
  await stack.disposeAsync();
  console.log('[1] does this line of code ever run?'); 
}
{
  {
    const neverResolves = Promise.withResolvers().promise;
    await using _ = {[Symbol.dispose]: () => neverResolves};
  }
  console.log('[2] does this line of code ever run?');
}

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