Skip to content

Commit b978f42

Browse files
committed
Add changes from hey-api/openapi-ts#171 to fix #1992
1 parent be7d53d commit b978f42

File tree

2 files changed

+39
-56
lines changed

2 files changed

+39
-56
lines changed

README.md

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,3 @@
1-
# Important announcement
2-
3-
> [!IMPORTANT]
4-
> Please migrate your projects to use [@hey-api/openapi-ts](https://github.com/hey-api/openapi-ts)
5-
6-
Due to time limitations on my end, this project has been unmaintained for a while now. The `@hey-api/openapi-ts`
7-
project started as a fork with the goal to resolve the most pressing issues. going forward they are planning to
8-
maintain the OpenAPI generator and give it the love it deserves. Please support them with their work and make
9-
sure to migrate your projects: https://heyapi.dev/openapi-ts/migrating.html#openapi-typescript-codegen
10-
11-
- All open PR's and issues will be archived on the 1st of May 2024
12-
- All versions of this package will be deprecated in NPM
13-
14-
👋 Thanks for all the support, downloads and love! Cheers Ferdi.
15-
16-
---
17-
181
# OpenAPI Typescript Codegen
192

203
[![NPM][npm-image]][npm-url]

src/templates/core/CancelablePromise.hbs

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -21,62 +21,62 @@ export interface OnCancel {
2121
}
2222

2323
export class CancelablePromise<T> implements Promise<T> {
24-
#isResolved: boolean;
25-
#isRejected: boolean;
26-
#isCancelled: boolean;
27-
readonly #cancelHandlers: (() => void)[];
28-
readonly #promise: Promise<T>;
29-
#resolve?: (value: T | PromiseLike<T>) => void;
30-
#reject?: (reason?: any) => void;
24+
private _isResolved: boolean;
25+
private _isRejected: boolean;
26+
private _isCancelled: boolean;
27+
readonly cancelHandlers: (() => void)[];
28+
readonly promise: Promise<T>;
29+
private _resolve?: (value: T | PromiseLike<T>) => void;
30+
private _reject?: (reason?: unknown) => void;
3131

3232
constructor(
3333
executor: (
3434
resolve: (value: T | PromiseLike<T>) => void,
35-
reject: (reason?: any) => void,
35+
reject: (reason?: unknown) => void,
3636
onCancel: OnCancel
3737
) => void
3838
) {
39-
this.#isResolved = false;
40-
this.#isRejected = false;
41-
this.#isCancelled = false;
42-
this.#cancelHandlers = [];
43-
this.#promise = new Promise<T>((resolve, reject) => {
44-
this.#resolve = resolve;
45-
this.#reject = reject;
39+
this._isResolved = false;
40+
this._isRejected = false;
41+
this._isCancelled = false;
42+
this.cancelHandlers = [];
43+
this.promise = new Promise<T>((resolve, reject) => {
44+
this._resolve = resolve;
45+
this._reject = reject;
4646

4747
const onResolve = (value: T | PromiseLike<T>): void => {
48-
if (this.#isResolved || this.#isRejected || this.#isCancelled) {
48+
if (this._isResolved || this._isRejected || this._isCancelled) {
4949
return;
5050
}
51-
this.#isResolved = true;
52-
if (this.#resolve) this.#resolve(value);
51+
this._isResolved = true;
52+
if (this._resolve) this._resolve(value);
5353
};
5454

55-
const onReject = (reason?: any): void => {
56-
if (this.#isResolved || this.#isRejected || this.#isCancelled) {
55+
const onReject = (reason?: unknown): void => {
56+
if (this._isResolved || this._isRejected || this._isCancelled) {
5757
return;
5858
}
59-
this.#isRejected = true;
60-
if (this.#reject) this.#reject(reason);
59+
this._isRejected = true;
60+
if (this._reject) this._reject(reason);
6161
};
6262

6363
const onCancel = (cancelHandler: () => void): void => {
64-
if (this.#isResolved || this.#isRejected || this.#isCancelled) {
64+
if (this._isResolved || this._isRejected || this._isCancelled) {
6565
return;
6666
}
67-
this.#cancelHandlers.push(cancelHandler);
67+
this.cancelHandlers.push(cancelHandler);
6868
};
6969

7070
Object.defineProperty(onCancel, 'isResolved', {
71-
get: (): boolean => this.#isResolved,
71+
get: (): boolean => this._isResolved,
7272
});
7373

7474
Object.defineProperty(onCancel, 'isRejected', {
75-
get: (): boolean => this.#isRejected,
75+
get: (): boolean => this._isRejected,
7676
});
7777

7878
Object.defineProperty(onCancel, 'isCancelled', {
79-
get: (): boolean => this.#isCancelled,
79+
get: (): boolean => this._isCancelled,
8080
});
8181

8282
return executor(onResolve, onReject, onCancel as OnCancel);
@@ -89,41 +89,41 @@ export class CancelablePromise<T> implements Promise<T> {
8989

9090
public then<TResult1 = T, TResult2 = never>(
9191
onFulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null,
92-
onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null
92+
onRejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null
9393
): Promise<TResult1 | TResult2> {
94-
return this.#promise.then(onFulfilled, onRejected);
94+
return this.promise.then(onFulfilled, onRejected);
9595
}
9696

9797
public catch<TResult = never>(
98-
onRejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null
98+
onRejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null
9999
): Promise<T | TResult> {
100-
return this.#promise.catch(onRejected);
100+
return this.promise.catch(onRejected);
101101
}
102102

103103
public finally(onFinally?: (() => void) | null): Promise<T> {
104-
return this.#promise.finally(onFinally);
104+
return this.promise.finally(onFinally);
105105
}
106106

107107
public cancel(): void {
108-
if (this.#isResolved || this.#isRejected || this.#isCancelled) {
108+
if (this._isResolved || this._isRejected || this._isCancelled) {
109109
return;
110110
}
111-
this.#isCancelled = true;
112-
if (this.#cancelHandlers.length) {
111+
this._isCancelled = true;
112+
if (this.cancelHandlers.length) {
113113
try {
114-
for (const cancelHandler of this.#cancelHandlers) {
114+
for (const cancelHandler of this.cancelHandlers) {
115115
cancelHandler();
116116
}
117117
} catch (error) {
118118
console.warn('Cancellation threw an error', error);
119119
return;
120120
}
121121
}
122-
this.#cancelHandlers.length = 0;
123-
if (this.#reject) this.#reject(new CancelError('Request aborted'));
122+
this.cancelHandlers.length = 0;
123+
if (this._reject) this._reject(new CancelError('Request aborted'));
124124
}
125125

126126
public get isCancelled(): boolean {
127-
return this.#isCancelled;
127+
return this._isCancelled;
128128
}
129129
}

0 commit comments

Comments
 (0)