Skip to content

Commit

Permalink
add isAborted to Abortable interface
Browse files Browse the repository at this point in the history
  • Loading branch information
sgratzl committed Dec 25, 2018
1 parent dce5680 commit a2d8021
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/abortAble.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export function isPromiseLike(p: PromiseLike<any> | any): p is PromiseLike<any>
export interface IAbortAblePromiseBase<T> extends PromiseLike<T> {
then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): IAbortAblePromiseBase<TResult1 | TResult2>;
abort(): void;
isAborted(): boolean;
}

export declare type IAbortAblePromise<T> = IAbortAblePromiseBase<T | symbol>;
Expand Down Expand Up @@ -33,7 +34,8 @@ function thenFactory<T>(loader: PromiseLike<T | symbol>, isAborted: () => boolea
});
return {
then: thenFactory(fullfiller, isAborted, abort),
abort
abort,
isAborted
};
}
return then;
Expand All @@ -60,7 +62,8 @@ export default function abortAble<T>(loader: PromiseLike<T>): IAAP<T> {

return {
then: thenFactory(race, isAborted, abort),
abort
abort,
isAborted
};
}

Expand Down Expand Up @@ -96,7 +99,8 @@ export function abortAbleAll(values: any[]): IAAP<any[]> {

return {
then: thenFactory(race, isAborted, abort),
abort
abort,
isAborted
};
}

Expand Down Expand Up @@ -125,11 +129,13 @@ export function abortAbleResolveNow<T>(value: T) {
}
return {
then: <any>abortAbleResolveNow(<TResult1>res),
abort: () => undefined
abort: () => undefined,
isAborted: () => false
};
}
return {
then,
abort: () => undefined
abort: () => undefined,
isAborted: () => false
};
}

0 comments on commit a2d8021

Please sign in to comment.