Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: refactor project to use PromiseWithResolvers #55436

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const {
ObjectAssign,
ObjectDefineProperty,
ObjectPrototypeHasOwnProperty,
PromiseWithResolvers,
RegExpPrototypeExec,
SafeSet,
StringPrototypeIncludes,
Expand All @@ -47,7 +48,6 @@ const {

const {
convertToValidSignal,
createDeferredPromise,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this isn't being used, you can remove it entirely, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it because it was not in use

getSystemErrorName,
kEmptyObject,
promisify,
Expand Down Expand Up @@ -237,7 +237,7 @@ function exec(command, options, callback) {

const customPromiseExecFunction = (orig) => {
return (...args) => {
const { promise, resolve, reject } = createDeferredPromise();
const { promise, resolve, reject } = PromiseWithResolvers();

promise.child = orig(...args, (err, stdout, stderr) => {
if (err !== null) {
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/abort_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const {
ObjectDefineProperty,
ObjectSetPrototypeOf,
PromiseResolve,
PromiseWithResolvers,
SafeFinalizationRegistry,
SafeSet,
SafeWeakRef,
Expand All @@ -28,7 +29,6 @@ const {
kWeakHandler,
} = require('internal/event_target');
const {
createDeferredPromise,
customInspectSymbol,
kEmptyObject,
kEnumerableProperty,
Expand Down Expand Up @@ -486,7 +486,7 @@ async function aborted(signal, resource) {
validateObject(resource, 'resource', kValidateObjectAllowObjects);
if (signal.aborted)
return PromiseResolve();
const abortPromise = createDeferredPromise();
const abortPromise = PromiseWithResolvers();
const opts = { __proto__: null, [kWeakHandler]: resource, once: true, [kResistStopPropagation]: true };
signal.addEventListener('abort', abortPromise.resolve, opts);
return abortPromise.promise;
Expand Down
6 changes: 3 additions & 3 deletions lib/internal/blob.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const {
ObjectSetPrototypeOf,
PromisePrototypeThen,
PromiseReject,
PromiseWithResolvers,
RegExpPrototypeExec,
RegExpPrototypeSymbolReplace,
StringPrototypeSplit,
Expand Down Expand Up @@ -47,7 +48,6 @@ const {
} = require('internal/util/types');

const {
createDeferredPromise,
customInspectSymbol: kInspect,
kEmptyObject,
kEnumerableProperty,
Expand Down Expand Up @@ -325,7 +325,7 @@ class Blob {
this.pendingPulls = [];
},
pull(c) {
const { promise, resolve, reject } = createDeferredPromise();
const { promise, resolve, reject } = PromiseWithResolvers();
this.pendingPulls.push({ resolve, reject });
const readNext = () => {
reader.pull((status, buffer) => {
Expand Down Expand Up @@ -478,7 +478,7 @@ function createBlobFromFilePath(path, options) {
}

function arrayBuffer(blob) {
const { promise, resolve, reject } = createDeferredPromise();
const { promise, resolve, reject } = PromiseWithResolvers();
const reader = blob[kHandle].getReader();
const buffers = [];
const readNext = () => {
Expand Down
6 changes: 3 additions & 3 deletions lib/internal/fs/watchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const {
FunctionPrototypeCall,
ObjectDefineProperty,
ObjectSetPrototypeOf,
PromiseWithResolvers,
Symbol,
} = primordials;

Expand All @@ -15,7 +16,6 @@ const {
},
} = require('internal/errors');
const {
createDeferredPromise,
kEmptyObject,
} = require('internal/util');

Expand Down Expand Up @@ -325,7 +325,7 @@ async function* watch(filename, options = kEmptyObject) {
throw new AbortError(undefined, { cause: signal?.reason });

const handle = new FSEvent();
let { promise, resolve, reject } = createDeferredPromise();
let { promise, resolve, reject } = PromiseWithResolvers();
const oncancel = () => {
handle.close();
reject(new AbortError(undefined, { cause: signal?.reason }));
Expand Down Expand Up @@ -368,7 +368,7 @@ async function* watch(filename, options = kEmptyObject) {

while (!signal?.aborted) {
yield await promise;
({ promise, resolve, reject } = createDeferredPromise());
({ promise, resolve, reject } = PromiseWithResolvers());
}
throw new AbortError(undefined, { cause: signal?.reason });
} finally {
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/test_runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const {
ObjectAssign,
PromisePrototypeThen,
PromiseResolve,
PromiseWithResolvers,
SafeMap,
SafePromiseAll,
SafePromiseAllReturnVoid,
Expand Down Expand Up @@ -63,7 +64,6 @@ const { getInspectPort, isUsingInspector, isInspectorMessage } = require('intern
const { isRegExp } = require('internal/util/types');
const { pathToFileURL } = require('internal/url');
const {
createDeferredPromise,
kEmptyObject,
} = require('internal/util');
const { kEmitMessage } = require('internal/test_runner/tests_stream');
Expand Down Expand Up @@ -744,7 +744,7 @@ function run(options = kEmptyObject) {
};
} else {
runFiles = async () => {
const { promise, resolve: finishBootstrap } = createDeferredPromise();
const { promise, resolve: finishBootstrap } = PromiseWithResolvers();

await root.runInAsyncScope(async () => {
const parentURL = pathToFileURL(cwd + sep).href;
Expand Down
12 changes: 6 additions & 6 deletions lib/internal/webstreams/adapters.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const {
ObjectEntries,
PromisePrototypeThen,
PromiseResolve,
PromiseWithResolvers,
SafePromiseAll,
SafePromisePrototypeFinally,
SafeSet,
Expand Down Expand Up @@ -64,7 +65,6 @@ const {
} = require('internal/errors');

const {
createDeferredPromise,
kEmptyObject,
normalizeEncoding,
} = require('internal/util');
Expand Down Expand Up @@ -213,7 +213,7 @@ function newWritableStreamFromStreamWritable(streamWritable) {

write(chunk) {
if (streamWritable.writableNeedDrain || !streamWritable.write(chunk)) {
backpressurePromise = createDeferredPromise();
backpressurePromise = PromiseWithResolvers();
return SafePromisePrototypeFinally(
backpressurePromise.promise, () => {
backpressurePromise = undefined;
Expand All @@ -227,7 +227,7 @@ function newWritableStreamFromStreamWritable(streamWritable) {

close() {
if (closed === undefined && !isWritableEnded(streamWritable)) {
closed = createDeferredPromise();
closed = PromiseWithResolvers();
streamWritable.end();
return closed.promise;
}
Expand Down Expand Up @@ -900,7 +900,7 @@ function newWritableStreamFromStreamBase(streamBase, strategy) {
}

function doWrite(chunk, controller) {
const promise = createDeferredPromise();
const promise = PromiseWithResolvers();
let ret;
let req;
try {
Expand Down Expand Up @@ -933,7 +933,7 @@ function newWritableStreamFromStreamBase(streamBase, strategy) {
},

close() {
const promise = createDeferredPromise();
const promise = PromiseWithResolvers();
const req = new ShutdownWrap();
req.oncomplete = () => promise.resolve();
const err = streamBase.shutdown(req);
Expand Down Expand Up @@ -1000,7 +1000,7 @@ function newReadableStreamFromStreamBase(streamBase, strategy, options = kEmptyO
},

cancel() {
const promise = createDeferredPromise();
const promise = PromiseWithResolvers();
try {
ondone();
} catch (error) {
Expand Down
26 changes: 13 additions & 13 deletions lib/internal/webstreams/readablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const {
PromisePrototypeThen,
PromiseReject,
PromiseResolve,
PromiseWithResolvers,
SafePromiseAll,
Symbol,
SymbolAsyncIterator,
Expand Down Expand Up @@ -50,7 +51,6 @@ const {
} = require('internal/util/types');

const {
createDeferredPromise,
customInspectSymbol: kInspect,
kEmptyObject,
kEnumerableProperty,
Expand Down Expand Up @@ -252,7 +252,7 @@ class ReadableStream {
validateObject(strategy, 'strategy', kValidateObjectAllowObjectsAndNull);
this[kState] = createReadableStreamState();

this[kIsClosedPromise] = createDeferredPromise();
this[kIsClosedPromise] = PromiseWithResolvers();
this[kControllerErrorFunction] = () => {};

// The spec requires handling of the strategy first
Expand Down Expand Up @@ -486,7 +486,7 @@ class ReadableStream {
new ERR_INVALID_STATE.TypeError(
'The reader is not bound to a ReadableStream'));
}
const promise = createDeferredPromise();
const promise = PromiseWithResolvers();

// eslint-disable-next-line no-use-before-define
readableStreamDefaultReaderRead(reader, new ReadableStreamAsyncIteratorReadRequest(reader, state, promise));
Expand Down Expand Up @@ -643,7 +643,7 @@ function InternalTransferredReadableStream() {
this[kType] = 'ReadableStream';
this[kState] = createReadableStreamState();

this[kIsClosedPromise] = createDeferredPromise();
this[kIsClosedPromise] = PromiseWithResolvers();
}

ObjectSetPrototypeOf(InternalTransferredReadableStream.prototype, ReadableStream.prototype);
Expand Down Expand Up @@ -786,7 +786,7 @@ class ReadableStreamAsyncIteratorReadRequest {

class DefaultReadRequest {
constructor() {
this[kState] = createDeferredPromise();
this[kState] = PromiseWithResolvers();
}

[kChunk](value) {
Expand All @@ -806,7 +806,7 @@ class DefaultReadRequest {

class ReadIntoRequest {
constructor() {
this[kState] = createDeferredPromise();
this[kState] = PromiseWithResolvers();
}

[kChunk](value) {
Expand Down Expand Up @@ -1230,7 +1230,7 @@ function InternalReadableStream(start, pull, cancel, highWaterMark, size) {
markTransferMode(this, false, true);
this[kType] = 'ReadableStream';
this[kState] = createReadableStreamState();
this[kIsClosedPromise] = createDeferredPromise();
this[kIsClosedPromise] = PromiseWithResolvers();
const controller = new ReadableStreamDefaultController(kSkipThrow);
setupReadableStreamDefaultController(
this,
Expand Down Expand Up @@ -1258,7 +1258,7 @@ function InternalReadableByteStream(start, pull, cancel) {
markTransferMode(this, false, true);
this[kType] = 'ReadableStream';
this[kState] = createReadableStreamState();
this[kIsClosedPromise] = createDeferredPromise();
this[kIsClosedPromise] = PromiseWithResolvers();
const controller = new ReadableByteStreamController(kSkipThrow);
setupReadableByteStreamController(
this,
Expand Down Expand Up @@ -1392,7 +1392,7 @@ function readableStreamPipeTo(
}
}

const promise = createDeferredPromise();
const promise = PromiseWithResolvers();

const state = {
currentWrite: PromiseResolve(),
Expand Down Expand Up @@ -1509,7 +1509,7 @@ function readableStreamPipeTo(

await writer[kState].ready.promise;

const promise = createDeferredPromise();
const promise = PromiseWithResolvers();
// eslint-disable-next-line no-use-before-define
readableStreamDefaultReaderRead(reader, new PipeToReadableStreamReadRequest(writer, state, promise));

Expand Down Expand Up @@ -1613,7 +1613,7 @@ function readableStreamDefaultTee(stream, cloneForBranch2) {
let reason2;
let branch1;
let branch2;
const cancelPromise = createDeferredPromise();
const cancelPromise = PromiseWithResolvers();

async function pullAlgorithm() {
if (reading) return;
Expand Down Expand Up @@ -1712,7 +1712,7 @@ function readableByteStreamTee(stream) {
let reason2;
let branch1;
let branch2;
const cancelDeferred = createDeferredPromise();
const cancelDeferred = PromiseWithResolvers();

function forwardReaderError(thisReader) {
PromisePrototypeThen(
Expand Down Expand Up @@ -2159,7 +2159,7 @@ function readableStreamReaderGenericInitialize(reader, stream) {
stream[kState].reader = reader;
switch (stream[kState].state) {
case 'readable':
reader[kState].close = createDeferredPromise();
reader[kState].close = PromiseWithResolvers();
break;
case 'closed':
reader[kState].close = {
Expand Down
9 changes: 3 additions & 6 deletions lib/internal/webstreams/transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const {
ObjectDefineProperties,
PromiseResolve,
PromiseWithResolvers,
ReflectConstruct,
} = primordials;

Expand All @@ -28,10 +29,6 @@ const {
writableStreamDefaultControllerErrorIfNeeded,
} = require('internal/webstreams/writablestream');

const {
createDeferredPromise,
} = require('internal/util');

const assert = require('internal/assert');

const {
Expand Down Expand Up @@ -181,7 +178,7 @@ class CrossRealmTransformWritableSink {
this[kState] = {
port,
controller: undefined,
backpressurePromise: createDeferredPromise(),
backpressurePromise: PromiseWithResolvers(),
unref,
};

Expand Down Expand Up @@ -239,7 +236,7 @@ class CrossRealmTransformWritableSink {
};
}
await this[kState].backpressurePromise.promise;
this[kState].backpressurePromise = createDeferredPromise();
this[kState].backpressurePromise = PromiseWithResolvers();
try {
this[kState].port.postMessage({ type: 'chunk', value: chunk });
} catch (error) {
Expand Down
Loading
Loading