title: ES Promise.withResolvers (2023)
  status: proposal
  stage: 2
  location: https://github.com/tc39/proposal-promise-with-resolvers
  copyright: false
  contributors: Peter Klecha

Introduction

This is the formal specification for a proposed `Promise.withResolvers` method in JavaScript. It modifies the original ECMAScript specification with several new or revised clauses. See the proposal's explainer for the proposal's background, motivation, and usage examples.

Control Abstraction Objects

Promise Objects

Properties of the Promise Constructor

Promise.withResolvers ( )

This function returns an object with three properties: a new promise plus the `resolve` and `reject` functions associated with that promise.

1. Let _C_ be the *this* value. 1. Let _promiseCapability_ be ? NewPromiseCapability(_C_). 1. Let _obj_ be OrdinaryObjectCreate(%Object.prototype%). 1. Perform ! CreateDataPropertyOrThrow(_obj_, "promise", _promiseCapability_.[[Promise]]). 1. Perform ! CreateDataPropertyOrThrow(_obj_, "resolve", _promiseCapability_.[[Resolve]]). 1. Perform ! CreateDataPropertyOrThrow(_obj_, "reject", _promiseCapability_.[[Reject]]). 1. Return _obj_.