跳至主要內容

Promise.withResolvers

小于 1 分钟featurees-proposal

Promise.withResolversopen in new window

模块

esnext.promise.with-resolversopen in new window

类型

interface PromiseConstructor {
  withResolvers<T>(): {
    promise: Promise<T>;
    resolve: (value: T | PromiseLike<T>) => void;
    reject: (reason?: any) => void;
  };
}

入口点

core-js/proposals/promise-with-resolvers
core-js(-pure)/full/promise/with-resolvers

示例

示例open in new window:

const d = Promise.withResolvers();
d.resolve(42);
d.promise.then(console.log); // => 42