@@ -23,13 +23,15 @@ export interface MakeCancelablePromise<T = unknown> {
23
23
* The wrapped promise that can be aborted
24
24
*/
25
25
promise : Promise < T > ;
26
+
26
27
/**
27
28
* Aborts the promise execution. Safe to call multiple times - subsequent calls will be ignored if already cancelled.
28
29
*/
29
- cancel : ( ) => void ;
30
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
+ cancel : ( reason ?: any ) => void ;
32
+
30
33
/**
31
34
* Checks whether the promise has been cancelled
32
- * @returns {boolean } True if the promise has been cancelled, false otherwise
33
35
*/
34
36
isCancelled : ( ) => boolean ;
35
37
}
@@ -94,7 +96,6 @@ export interface MakeCancelablePromise<T = unknown> {
94
96
*/
95
97
export function makeCancelable < T = unknown > ( promise : Promise < T > ) : MakeCancelablePromise < T > {
96
98
const controller = new AbortController ( ) ;
97
- let isCancelled = false ;
98
99
99
100
const wrappedPromise = new Promise < T > ( ( resolve , reject ) => {
100
101
// Early return if already cancelled
@@ -105,7 +106,6 @@ export function makeCancelable<T = unknown>(promise: Promise<T>): MakeCancelable
105
106
106
107
// Add abort signal listener
107
108
const abortHandler = ( ) => {
108
- isCancelled = true ;
109
109
reject ( new AbortPromiseError ( ) ) ;
110
110
} ;
111
111
@@ -133,13 +133,14 @@ export function makeCancelable<T = unknown>(promise: Promise<T>): MakeCancelable
133
133
134
134
return {
135
135
promise : wrappedPromise ,
136
- cancel ( ) {
137
- if ( ! isCancelled ) {
138
- controller . abort ( ) ;
136
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
137
+ cancel ( reason ?: any ) {
138
+ if ( ! controller . signal . aborted ) {
139
+ controller . abort ( reason ) ;
139
140
}
140
141
} ,
141
142
isCancelled ( ) {
142
- return isCancelled ;
143
+ return controller . signal . aborted ;
143
144
} ,
144
145
} ;
145
146
}
0 commit comments