Skip to content

Deprecate AbortSignal on resources that are not actions #48725

Open
@benjamingr

Description

@benjamingr

We currently have several APIs that support AbortSignals like:

  • http.Server
  • stream.Readable / stream.Writable
  • child_process methods returning a child (and not a promise)
  • addAbortSignal

Those APIs are resources and not actions and support Symbol.dispose Symbol.asyncDispose.

Since they are disposables, we should deprecate support for AbortSignal on APIs that are resources and not actions (while keeping AbortSignal on APIs that are actions (e.g. return promises)) and encourage the safe helper we added for addAbortListener on those updating our docs.

Basically instead of:

function foo() {
  const ac = new AbortController();
  const httpServer = /* */
  httpServer.listen(3000, { signal: ac.signal });
 
  return someAsyncAction().then(() => ac.abort()); // close the server
}

We should encourage:

async function foo() {
  using httpServer = /* */
  httpServer.listen(3000);
  await someAsyncAction()
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    abortcontrollerIssues and PRs related to the AbortController APIhttpIssues or PRs related to the http subsystem.streamIssues and PRs related to the stream subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions