Skip to content
This repository was archived by the owner on Dec 18, 2025. It is now read-only.

Commit c72961a

Browse files
committed
Attached progress to promisify and added once for load and error events
1 parent dbd1ec7 commit c72961a

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/ajax.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,21 @@ class Ajax<T> extends Events {
206206
}
207207
}
208208

209-
promisify() {
209+
/**
210+
* @param onprogress - The progress callback.
211+
* @returns A promise that resolves with the response.
212+
*/
213+
promisify(onprogress: (progress: number) => void) {
214+
this.unbind('progress');
215+
if (onprogress) {
216+
this.on('progress', onprogress);
217+
}
218+
this.on('progress', onprogress);
210219
return new Promise<T>((resolve, reject) => {
211-
this.on('load', (_status, response: T) => {
220+
this.once('load', (_status, response: T) => {
212221
resolve(response);
213222
});
214-
this.on('error', (_status, error) => {
223+
this.once('error', (_status, error) => {
215224
reject(error);
216225
});
217226
});

0 commit comments

Comments
 (0)