mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
util: add internal createDeferredPromise()
The pattern of resolving/rejecting a Promise from outside of its executor happens numerous times throughout the codebase (more than what is updated here in fact). This commit abstracts that logic into an internal utility function. PR-URL: https://github.com/nodejs/node/pull/37095 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Zijian Liu <lxxyxzj@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
fec093b6b7
commit
17467d15f8
3 changed files with 16 additions and 18 deletions
|
@ -3,7 +3,6 @@
|
|||
const {
|
||||
ArrayFrom,
|
||||
ObjectSetPrototypeOf,
|
||||
Promise,
|
||||
PromiseResolve,
|
||||
RegExpPrototypeTest,
|
||||
StringPrototypeToLowerCase,
|
||||
|
@ -29,6 +28,7 @@ const {
|
|||
} = require('internal/util/types');
|
||||
|
||||
const {
|
||||
createDeferredPromise,
|
||||
customInspectSymbol: kInspect,
|
||||
emitExperimentalWarning,
|
||||
} = require('internal/util');
|
||||
|
@ -56,15 +56,6 @@ const kLength = Symbol('kLength');
|
|||
|
||||
let Buffer;
|
||||
|
||||
function deferred() {
|
||||
let res, rej;
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
res = resolve;
|
||||
rej = reject;
|
||||
});
|
||||
return { promise, resolve: res, reject: rej };
|
||||
}
|
||||
|
||||
function lazyBuffer() {
|
||||
if (Buffer === undefined)
|
||||
Buffer = require('buffer').Buffer;
|
||||
|
@ -210,7 +201,7 @@ class Blob extends JSTransferable {
|
|||
promise,
|
||||
resolve,
|
||||
reject
|
||||
} = deferred();
|
||||
} = createDeferredPromise();
|
||||
job.ondone = (err, ab) => {
|
||||
if (err !== undefined)
|
||||
return reject(new AbortError());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue