Skip to content

Commit 2162fd8

Browse files
committed
use arrow functions to not lose context for this
1 parent 381fd53 commit 2162fd8

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/execution/publisher.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,20 @@ export class Publisher<TSource extends Source, TIncremental, TPayload> {
7070

7171
subscribe(): AsyncGenerator<TPayload, void, void> {
7272
let isDone = false;
73-
const publisher = this;
7473

75-
async function next(): Promise<IteratorResult<TPayload, void>> {
74+
const next = async (): Promise<IteratorResult<TPayload, void>> => {
7675
if (isDone) {
7776
return { value: undefined, done: true };
7877
}
7978

80-
await Promise.race(Array.from(publisher.sources).map((p) => p.promise));
79+
await Promise.race(Array.from(this.sources).map((p) => p.promise));
8180

8281
if (isDone) {
8382
return { value: undefined, done: true };
8483
}
8584

86-
const incremental = publisher.getCompletedIncrementalResults();
87-
const hasNext = publisher.sources.size > 0;
85+
const incremental = this.getCompletedIncrementalResults();
86+
const hasNext = this.sources.size > 0;
8887

8988
if (!incremental.length && hasNext) {
9089
return next();
@@ -95,20 +94,20 @@ export class Publisher<TSource extends Source, TIncremental, TPayload> {
9594
}
9695

9796
return {
98-
value: publisher.toPayload(incremental, hasNext),
97+
value: this.toPayload(incremental, hasNext),
9998
done: false,
10099
};
101-
}
100+
};
102101

103-
function returnIterators() {
102+
const returnIterators = () => {
104103
const promises: Array<Promise<IteratorResult<unknown>>> = [];
105-
publisher.sources.forEach((source) => {
104+
this.sources.forEach((source) => {
106105
if (source.iterator?.return) {
107106
promises.push(source.iterator.return());
108107
}
109108
});
110109
return Promise.all(promises);
111-
}
110+
};
112111

113112
return {
114113
[Symbol.asyncIterator]() {

0 commit comments

Comments
 (0)