Skip to content

Commit beccf2d

Browse files
authored
Merge pull request #1627 from pitmullerIngka/fix/next-promise-resolve
fix: adjust promise resolve for next issue
2 parents 1095d07 + 11f84f5 commit beccf2d

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/templates/core/CancelablePromise.hbs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ export class CancelablePromise<T> implements Promise<T> {
4949
return;
5050
}
5151
this.#isResolved = true;
52-
this.#resolve?.(value);
52+
if (this.#resolve) this.#resolve(value);
5353
};
5454

5555
const onReject = (reason?: any): void => {
5656
if (this.#isResolved || this.#isRejected || this.#isCancelled) {
5757
return;
5858
}
5959
this.#isRejected = true;
60-
this.#reject?.(reason);
60+
if (this.#reject) this.#reject(reason);
6161
};
6262

6363
const onCancel = (cancelHandler: () => void): void => {
@@ -120,7 +120,7 @@ export class CancelablePromise<T> implements Promise<T> {
120120
}
121121
}
122122
this.#cancelHandlers.length = 0;
123-
this.#reject?.(new CancelError('Request aborted'));
123+
if (this.#reject) this.#reject(new CancelError('Request aborted'));
124124
}
125125

126126
public get isCancelled(): boolean {

test/__snapshots__/index.spec.ts.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,15 @@ export class CancelablePromise<T> implements Promise<T> {
119119
return;
120120
}
121121
this.#isResolved = true;
122-
this.#resolve?.(value);
122+
if (this.#resolve) this.#resolve(value);
123123
};
124124

125125
const onReject = (reason?: any): void => {
126126
if (this.#isResolved || this.#isRejected || this.#isCancelled) {
127127
return;
128128
}
129129
this.#isRejected = true;
130-
this.#reject?.(reason);
130+
if (this.#reject) this.#reject(reason);
131131
};
132132

133133
const onCancel = (cancelHandler: () => void): void => {
@@ -3345,15 +3345,15 @@ export class CancelablePromise<T> implements Promise<T> {
33453345
return;
33463346
}
33473347
this.#isResolved = true;
3348-
this.#resolve?.(value);
3348+
if (this.#resolve) this.#resolve(value);
33493349
};
33503350

33513351
const onReject = (reason?: any): void => {
33523352
if (this.#isResolved || this.#isRejected || this.#isCancelled) {
33533353
return;
33543354
}
33553355
this.#isRejected = true;
3356-
this.#reject?.(reason);
3356+
if (this.#reject) this.#reject(reason);
33573357
};
33583358

33593359
const onCancel = (cancelHandler: () => void): void => {

0 commit comments

Comments
 (0)