Skip to content

Commit aed96a4

Browse files
committed
Neater
1 parent d9ccc82 commit aed96a4

File tree

10 files changed

+19
-39
lines changed

10 files changed

+19
-39
lines changed

grafast/dataplan-pg/src/adaptors/pg.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -660,8 +660,7 @@ export class PgSubscriber<
660660
Object.values(this.topics).forEach((iterators) => {
661661
if (iterators) {
662662
for (const iterator of iterators) {
663-
const r = iterator.throw!(e);
664-
r.then(null, noop);
663+
iterator.throw!(e).then(null, noop);
665664
}
666665
}
667666
});
@@ -741,11 +740,9 @@ export class PgSubscriber<
741740
for (const topic of Object.keys(this.topics)) {
742741
for (const asyncIterableIterator of this.topics[topic]!) {
743742
if (asyncIterableIterator.return) {
744-
const result = asyncIterableIterator.return();
745-
result.then(null, noop);
743+
asyncIterableIterator.return().then(null, noop);
746744
} else if (asyncIterableIterator.throw) {
747-
const result = asyncIterableIterator.throw(new Error("Released"));
748-
result.then(null, noop);
745+
asyncIterableIterator.throw(new Error("Released")).then(null, noop);
749746
} else {
750747
// What do we do now?!
751748
// TYPES: if instead of using an AsyncIterableIterator we required it was an AsyncGenerator then this problem would go away.

grafast/dataplan-pg/src/executor.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -899,9 +899,7 @@ ${duration}
899899
batch.forEach(({ resultIndex }) => {
900900
const stream = streams[resultIndex];
901901
if (isAsyncIterable(stream)) {
902-
const it = stream[Symbol.asyncIterator]();
903-
const r = it.throw?.(e);
904-
r?.then(null, noop);
902+
stream[Symbol.asyncIterator]().throw?.(e)?.then(null, noop);
905903
}
906904
const ep = Promise.reject(e);
907905
// Avoid unhandled promise rejection errors

grafast/dataplan-pg/src/steps/pgSelect.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,8 +1255,7 @@ export class PgSelectStep<
12551255
} else if (streamInitialCount != null && l < streamInitialCount) {
12561256
done = true;
12571257
const r = innerIterator.return?.();
1258-
r?.then(null, noop);
1259-
return Promise.resolve({ value: undefined, done });
1258+
return r ?? Promise.resolve({ value: undefined, done });
12601259
} else {
12611260
return innerIterator.next();
12621261
}

grafast/grafast/src/engine/distributor.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,7 @@ export function distributor<TData>(
381381
}
382382

383383
const onAbort = () => {
384-
const result = iterator.return();
385-
result.then(null, noop);
384+
iterator.return().then(null, noop);
386385
};
387386
const iterator = {
388387
[Symbol.asyncIterator]() {

grafast/grafast/src/prepare.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -224,18 +224,15 @@ const finalize = (
224224
promise.then(
225225
() => {
226226
iterator.push({ hasNext: false });
227-
const result = iterator.return(undefined);
228-
result.then(null, noop);
227+
iterator.return(undefined).then(null, noop);
229228
},
230229
(e) => {
231-
const result = iterator.throw(e);
232-
result.then(null, noop);
230+
iterator.throw(e).then(null, noop);
233231
},
234232
);
235233
} else {
236234
iterator.push({ hasNext: false });
237-
const result = iterator.return(undefined);
238-
result.then(null, noop);
235+
iterator.return(undefined).then(null, noop);
239236
}
240237

241238
return iterator;
@@ -517,8 +514,7 @@ function executePreemptive(
517514
break;
518515
}
519516
if (!next) {
520-
const result = iterator.throw(new Error("Invalid iteration"));
521-
result.then(null, noop);
517+
iterator.throw(new Error("Invalid iteration")).then(null, noop);
522518
break;
523519
}
524520
const { done, value } = next;
@@ -764,8 +760,7 @@ function newIterator<T = any>(
764760
} catch (e) {
765761
// ignore
766762
}
767-
const result = this.throw(e);
768-
result.then(null, noop);
763+
this.throw(e).then(null, noop);
769764
},
770765
);
771766
} else {

grafast/grafserv/src/mapIterator.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,12 @@ export function mapIterator<T, U>(
5252
},
5353
return(value) {
5454
status = 2;
55-
const r = iterator.return?.(value);
56-
r?.then(null, noop);
55+
iterator.return?.(value)?.then(null, noop);
5756
return Promise.resolve({ value: undefined, done: true });
5857
},
5958
throw(error) {
6059
status = 2;
61-
const r = iterator.throw?.(error);
62-
r?.then(null, noop);
60+
iterator.throw?.(error)?.then(null, noop);
6361
return Promise.reject(error);
6462
},
6563
[Symbol.asyncIterator]() {

grafast/grafserv/src/servers/fastify/v4/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,9 @@ export class FastifyGrafserv extends GrafservBase {
143143
if (!bufferIteratorHandled) {
144144
try {
145145
if (bufferIterator.return) {
146-
const result = bufferIterator.return();
147-
result.then(null, noop);
146+
bufferIterator.return().then(null, noop);
148147
} else if (bufferIterator.throw) {
149-
const result = bufferIterator.throw(e);
150-
result.then(null, noop);
148+
bufferIterator.throw(e).then(null, noop);
151149
}
152150
} catch (e2) {
153151
/* nom nom nom */

grafast/grafserv/src/servers/h3/v1/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,9 @@ export class H3Grafserv extends GrafservBase {
199199
if (!bufferIteratorHandled) {
200200
try {
201201
if (bufferIterator.return) {
202-
const result = bufferIterator.return();
203-
result.then(null, noop);
202+
bufferIterator.return().then(null, noop);
204203
} else if (bufferIterator.throw) {
205-
const result = bufferIterator.throw(e);
206-
result.then(null, noop);
204+
bufferIterator.throw(e).then(null, noop);
207205
}
208206
} catch (e2) {
209207
/* nom nom nom */

grafast/grafserv/src/servers/node/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,7 @@ export class NodeGrafservBase extends GrafservBase {
203203
// Clean up when connection closes.
204204
const cleanup = () => {
205205
try {
206-
const r = bufferIterator.return?.();
207-
r?.then(null, noop);
206+
bufferIterator.return?.()?.then(null, noop);
208207
} catch {
209208
/* nom nom nom */
210209
}

postgraphile/postgraphile/__tests__/helpers.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,7 @@ export async function runTestQuery(
511511
if (operationType === "subscription") {
512512
const iterator = result[Symbol.asyncIterator]();
513513
// Terminate the subscription
514-
const r = iterator.return?.();
515-
r?.then(null, noop);
514+
iterator.return?.()?.then(null, noop);
516515
}
517516

518517
// Now wait for all payloads to have been collected

0 commit comments

Comments
 (0)