Promise.withResolvers
小于 1 分钟
Promise.withResolvers
模块
类型
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
示例
示例:
const d = Promise.withResolvers();
d.resolve(42);
d.promise.then(console.log); // => 42