Skip to content

Commit 3021de5

Browse files
authored
refactor(executor): rename finished state to aborted (#4647)
1 parent 2a87e39 commit 3021de5

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

src/execution/Executor.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ export class Executor<
222222
TAlternativeInitialResponse = ExecutionResult, // No alternative by default
223223
> {
224224
validatedExecutionArgs: ValidatedExecutionArgs;
225-
finished: boolean;
225+
aborted: boolean;
226226
collectedErrors: CollectedErrors;
227227
internalAbortController: AbortController;
228228
resolverAbortController: AbortController | undefined;
@@ -233,7 +233,7 @@ export class Executor<
233233
sharedResolverAbortSignal?: AbortSignal,
234234
) {
235235
this.validatedExecutionArgs = validatedExecutionArgs;
236-
this.finished = false;
236+
this.aborted = false;
237237
this.collectedErrors = new CollectedErrors();
238238
this.internalAbortController = new AbortController();
239239

@@ -329,16 +329,16 @@ export class Executor<
329329
}
330330

331331
abort(reason?: unknown): PromiseOrValue<void> {
332-
if (!this.finished) {
332+
if (!this.aborted) {
333333
this.finish();
334334
this.internalAbortController.abort(reason);
335335
this.resolverAbortController?.abort(reason);
336336
}
337337
}
338338

339339
finish(): void {
340-
if (!this.finished) {
341-
this.finished = true;
340+
if (!this.aborted) {
341+
this.aborted = true;
342342
}
343343
this.internalAbortController.signal.throwIfAborted();
344344
}
@@ -422,8 +422,8 @@ export class Executor<
422422
return promiseReduce(
423423
groupedFieldSet,
424424
(results, [responseName, fieldDetailsList]) => {
425-
if (this.finished) {
426-
throw new Error('Execution has already completed.');
425+
if (this.aborted) {
426+
throw new Error('Aborted!');
427427
}
428428
const fieldPath = addPath(path, responseName, parentType.name);
429429
const result = this.executeField(
@@ -597,8 +597,8 @@ export class Executor<
597597
fieldDetailsList: FieldDetailsList,
598598
path: Path,
599599
): void {
600-
if (this.finished) {
601-
throw new Error('Execution has already completed.');
600+
if (this.aborted) {
601+
throw new Error('Aborted!');
602602
}
603603

604604
const error = locatedError(
@@ -741,8 +741,8 @@ export class Executor<
741741
): Promise<unknown> {
742742
try {
743743
const resolved = await result;
744-
if (this.finished) {
745-
throw new Error('Execution has already completed.');
744+
if (this.aborted) {
745+
throw new Error('Aborted!');
746746
}
747747
let completed = this.completeValue(
748748
returnType,
@@ -812,7 +812,7 @@ export class Executor<
812812
pathToArray(path),
813813
);
814814
}
815-
if (this.finished || iteration.done) {
815+
if (this.aborted || iteration.done) {
816816
break;
817817
}
818818
const item = iteration.value;
@@ -843,12 +843,12 @@ export class Executor<
843843
}
844844

845845
// Throwing on completion outside of the loop may allow engines to better optimize
846-
if (this.finished) {
846+
if (this.aborted) {
847847
if (!iteration?.done) {
848848
// eslint-disable-next-line @typescript-eslint/no-floating-promises
849849
returnIteratorCatchingErrors(asyncIterator);
850850
}
851-
throw new Error('Execution has already completed.');
851+
throw new Error('Aborted!');
852852
}
853853

854854
return containsPromise ? Promise.all(completedResults) : completedResults;
@@ -1081,8 +1081,8 @@ export class Executor<
10811081
): Promise<unknown> {
10821082
try {
10831083
const resolved = await item;
1084-
if (this.finished) {
1085-
throw new Error('Execution has already completed.');
1084+
if (this.aborted) {
1085+
throw new Error('Aborted!');
10861086
}
10871087
let completed = this.completeValue(
10881088
itemType,
@@ -1137,8 +1137,8 @@ export class Executor<
11371137

11381138
if (isPromise(runtimeType)) {
11391139
return runtimeType.then((resolvedRuntimeType) => {
1140-
if (this.finished) {
1141-
throw new Error('Execution has already completed.');
1140+
if (this.aborted) {
1141+
throw new Error('Aborted!');
11421142
}
11431143
return this.completeObjectValue(
11441144
this.ensureValidRuntimeType(
@@ -1247,8 +1247,8 @@ export class Executor<
12471247

12481248
if (isPromise(isTypeOf)) {
12491249
return isTypeOf.then((resolvedIsTypeOf) => {
1250-
if (this.finished) {
1251-
throw new Error('Execution has already completed.');
1250+
if (this.aborted) {
1251+
throw new Error('Aborted!');
12521252
}
12531253
if (!resolvedIsTypeOf) {
12541254
throw this.invalidReturnTypeError(

0 commit comments

Comments
 (0)