123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- export interface OnCancelFunction {
- (cancelHandler: () => void): void;
- shouldReject: boolean;
- }
- declare class PCancelable<ValueType> extends Promise<ValueType> {
-
- static fn<ReturnType>(
- userFn: (onCancel: OnCancelFunction) => PromiseLike<ReturnType>
- ): () => PCancelable<ReturnType>;
- static fn<Agument1Type, ReturnType>(
- userFn: (
- argument1: Agument1Type,
- onCancel: OnCancelFunction
- ) => PromiseLike<ReturnType>
- ): (argument1: Agument1Type) => PCancelable<ReturnType>;
- static fn<Agument1Type, Agument2Type, ReturnType>(
- userFn: (
- argument1: Agument1Type,
- argument2: Agument2Type,
- onCancel: OnCancelFunction
- ) => PromiseLike<ReturnType>
- ): (
- argument1: Agument1Type,
- argument2: Agument2Type
- ) => PCancelable<ReturnType>;
- static fn<Agument1Type, Agument2Type, Agument3Type, ReturnType>(
- userFn: (
- argument1: Agument1Type,
- argument2: Agument2Type,
- argument3: Agument3Type,
- onCancel: OnCancelFunction
- ) => PromiseLike<ReturnType>
- ): (
- argument1: Agument1Type,
- argument2: Agument2Type,
- argument3: Agument3Type
- ) => PCancelable<ReturnType>;
- static fn<Agument1Type, Agument2Type, Agument3Type, Agument4Type, ReturnType>(
- userFn: (
- argument1: Agument1Type,
- argument2: Agument2Type,
- argument3: Agument3Type,
- argument4: Agument4Type,
- onCancel: OnCancelFunction
- ) => PromiseLike<ReturnType>
- ): (
- argument1: Agument1Type,
- argument2: Agument2Type,
- argument3: Agument3Type,
- argument4: Agument4Type
- ) => PCancelable<ReturnType>;
- static fn<
- Agument1Type,
- Agument2Type,
- Agument3Type,
- Agument4Type,
- Agument5Type,
- ReturnType
- >(
- userFn: (
- argument1: Agument1Type,
- argument2: Agument2Type,
- argument3: Agument3Type,
- argument4: Agument4Type,
- argument5: Agument5Type,
- onCancel: OnCancelFunction
- ) => PromiseLike<ReturnType>
- ): (
- argument1: Agument1Type,
- argument2: Agument2Type,
- argument3: Agument3Type,
- argument4: Agument4Type,
- argument5: Agument5Type
- ) => PCancelable<ReturnType>;
- static fn<ReturnType>(
- userFn: (...arguments: unknown[]) => PromiseLike<ReturnType>
- ): (...arguments: unknown[]) => PCancelable<ReturnType>;
-
- constructor(
- executor: (
- resolve: (value?: ValueType | PromiseLike<ValueType>) => void,
- reject: (reason?: unknown) => void,
- onCancel: OnCancelFunction
- ) => void
- );
- /**
- * Whether the promise is canceled.
- */
- readonly isCanceled: boolean;
- /**
- * Cancel the promise and optionally provide a reason.
- *
- * The cancellation is synchronous. Calling it after the promise has settled or multiple times does nothing.
- *
- * @param reason - The cancellation reason to reject the promise with.
- */
- cancel(reason?: string): void;
- }
- export default PCancelable;
- /**
- * Rejection reason when `.cancel()` is called.
- *
- * It includes a `.isCanceled` property for convenience.
- */
- export class CancelError extends Error {
- readonly name: 'CancelError';
- readonly isCanceled: true;
- constructor(reason?: string);
- }
|