SOLFIND
Web Lens
Portal home

CancellablePromise | TypeDoc Example

https://typedoc.org/example/classes/CancellablePromise.html • 146 KB fetched
Open original page


CancellablePromise | TypeDoc Example TypeDoc Example Docs API GitHub Preparing search index... * CancellablePromise Class CancellablePromise<T> This example shows off how TypeDoc handles * Complex method signatures * Static methods * A method with 10 overload signatures. Wow! * Only the implementation signature has a doc comment. TypeDoc automatically copies the comment from the implementation signature to each of the visible signatures if they don't have one. A promise with a cancel method. If canceled, the CancellablePromise will reject with a Cancellation object. Originally from real-cancellable-promise . Type Parameters * T what the CancellablePromise resolves to * Defined in example/src/classes/CancellablePromise.ts:52 Index Constructors constructor Properties promise cancel Methods Descriptions can be added for groups with @groupDescription , which will show up in the index where groups are listed. This works for both manually created groups which are created with @group , and implicit groups like the Methods group that this description is attached to. then catch finally resolve reject all all Settled race delay Constructors constructor * new CancellablePromise < T > (      promise : PromiseLike < T > ,      cancel : ( reason ?: string ) => void , ) : CancellablePromise < T > Type Parameters * T what the CancellablePromise resolves to Parameters * promise : PromiseLike < T > a normal promise or thenable * cancel : ( reason ?: string ) => void a function that cancels promise . Calling cancel after promise has resolved must be a no-op. Returns CancellablePromise < T > * Defined in example/src/classes/CancellablePromise.ts:76 Properties Protected Readonly promise promise : Promise < T > As a consumer of the library, you shouldn't ever need to access CancellablePromise.promise directly. If you are subclassing CancellablePromise for some reason, you can access this property. * Defined in example/src/classes/CancellablePromise.ts:60 Readonly cancel cancel : ( reason ?: string ) => void Cancel the CancellablePromise . * Defined in example/src/classes/CancellablePromise.ts:69 Methods then * then < TResult1 = T , TResult2 = never > (      onFulfilled ?: ( ( value : T ) => TResult1 | PromiseLike < TResult1 > ) | null ,      onRejected ?: ( ( reason : any ) => TResult2 | PromiseLike < TResult2 > ) | null , ) : CancellablePromise < TResult1 | TResult2 > Analogous to Promise.then . onFulfilled on onRejected can return a value, a normal promise, or a CancellablePromise . So you can make a chain a CancellablePromise s like this: const overallPromise = cancellableAsyncFunction1 () . then ( cancellableAsyncFunction2 ) . then ( cancellableAsyncFunction3 ) . then ( cancellableAsyncFunction4 ) Copy Then if you call overallPromise.cancel , cancel is called on all CancellablePromise s in the chain! In practice, this means that whichever async operation is in progress will be canceled. Type Parameters * TResult1 = T * TResult2 = never Parameters * Optional onFulfilled : ( ( value : T ) => TResult1 | PromiseLike < TResult1 > ) | null * Optional onRejected : ( ( reason : any ) => TResult2 | PromiseLike < TResult2 > ) | null Returns CancellablePromise < TResult1 | TResult2 > a new CancellablePromise * Defined in example/src/classes/CancellablePromise.ts:101 catch * catch < TResult = never > (      onRejected ?: ( ( reason : any ) => TResult | PromiseLike < TResult > ) | null , ) : CancellablePromise < T | TResult > Analogous to Promise.catch . Type Parameters * TResult = never Parameters * Optional onRejected : ( ( reason : any ) => TResult | PromiseLike < TResult > ) | null Returns CancellablePromise < T | TResult > * Defined in example/src/classes/CancellablePromise.ts:152 finally * finally ( onFinally ?: ( () => void ) | null ) : CancellablePromise < T > Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The resolved value cannot be modified from the callback. Parameters * Optional onFinally : ( () => void ) | null The callback to execute when the Promise is settled (fulfilled or rejected). Returns CancellablePromise < T > A Promise for the completion of the callback. * Defined in example/src/classes/CancellablePromise.ts:169 Static resolve * resolve () : CancellablePromise < void > Analogous to Promise.resolve . The returned promise should resolve even if it is canceled. The idea is that the promise is resolved instantaneously, so by the time the promise is canceled, it has already resolved. Returns CancellablePromise < void > * Defined in example/src/classes/CancellablePromise.ts:185 * resolve < T > ( value : T ) : CancellablePromise < T > Analogous to Promise.resolve . The returned promise should resolve even if it is canceled. The idea is that the promise is resolved instantaneously, so by the time the promise is canceled, it has already resolved. Type Parameters * T Parameters * value : T Returns CancellablePromise < T > * Defined in example/src/classes/CancellablePromise.ts:187 Static reject * reject < T > ( reason ?: unknown ) : CancellablePromise < T > Analogous to Promise.reject . Like CancellablePromise.resolve , canceling the returned CancellablePromise is a no-op. Type Parameters * T Parameters * Optional reason : unknown this should probably be an Error object Returns CancellablePromise < T > * Defined in example/src/classes/CancellablePromise.ts:201 Static all * all < T1 , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 > (      values : readonly [          T1          | PromiseLike < T1 > ,          T2 | PromiseLike < T2 > ,          T3 | PromiseLike < T3 > ,          T4 | PromiseLike < T4 > ,          T5 | PromiseLike < T5 > ,          T6 | PromiseLike < T6 > ,          T7 | PromiseLike < T7 > ,          T8 | PromiseLike < T8 > ,          T9 | PromiseLike < T9 > ,          T10 | PromiseLike < T10 > ,      ] , ) : CancellablePromise < [ T1 , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 ] > Type Parameters * T1 * T2 * T3 * T4 * T5 * T6 * T7 * T8 * T9 * T10 Parameters * values : readonly [      T1      | PromiseLike < T1 > ,      T2 | PromiseLike < T2 > ,      T3 | PromiseLike < T3 > ,      T4 | PromiseLike < T4 > ,      T5 | PromiseLike < T5 > ,      T6 | PromiseLike < T6 > ,      T7 | PromiseLike < T7 > ,      T8 | PromiseLike < T8 > ,      T9 | PromiseLike < T9 > ,      T10 | PromiseLike < T10 > , ] Returns CancellablePromise < [ T1 , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 ] > * Defined in example/src/classes/CancellablePromise.ts:205 * all < T1 , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 > (      values : readonly [          T1          | PromiseLike < T1 > ,          T2 | PromiseLike < T2 > ,          T3 | PromiseLike < T3 > ,          T4 | PromiseLike < T4 > ,          T5 | PromiseLike < T5 > ,          T6 | PromiseLike < T6 > ,          T7 | PromiseLike < T7 > ,          T8 | PromiseLike < T8 > ,          T9 | PromiseLike < T9 > ,      ] , ) : CancellablePromise < [ T1 , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 ] > Type Parameters * T1 * T2 * T3 * T4 * T5 * T6 * T7 * T8 * T9 Parameters * values : readonly [      T1      | PromiseLike < T1 > ,      T2 | PromiseLike < T2 > ,      T3 | PromiseLike < T3 > ,      T4 | PromiseLike < T4 > ,      T5 | PromiseLike < T5 > ,      T6 | PromiseLike < T6 > ,      T7 | PromiseLike < T7 > ,      T8 | PromiseLike < T8 > ,      T9 | PromiseLike < T9 > , ] Returns CancellablePromise < [ T1 , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 ] > * Defined in example/src/classes/CancellablePromise.ts:220 * all < T1 , T2 , T3 , T4 , T5 , T6 , T7 , T8 > (      values : readonly [          T1          | PromiseLike < T1 > ,          T2 | PromiseLike < T2 > ,          T3 | PromiseLike < T3 > ,          T4 | PromiseLike < T4 > ,          T5 | PromiseLike < T5 > ,          T6 | PromiseLike < T6 > ,          T7 | PromiseLike < T7 > ,          T8 | PromiseLike < T8 > ,      ] , ) : CancellablePromise < [ T1 , T2 , T3 , T4 , T5 , T6 , T7 , T8 ] > Type Parameters * T1 * T2 * T3 * T4 * T5 * T6 * T7 * T8 Parameters * values : readonly [      T1      | PromiseLike < T1 > ,      T2 | PromiseLike < T2 > ,      T3 | PromiseLike < T3 > ,      T4 | PromiseLike < T4 > ,      T5 | PromiseLike < T5 > ,      T6 | PromiseLike < T6 > ,      T7 | PromiseLike < T7 > ,      T8 | PromiseLike < T8 > , ] Returns CancellablePromise < [ T1 , T2 , T3 , T4 , T5 , T6 , T7 , T8 ] > * Defined in example/src/classes/CancellablePromise.ts:234 * all < T1 , T2 , T3 , T4 , T5 , T6 , T7 > (      values : readonly [          T1          | PromiseLike < T1 > ,          T2 | PromiseLike < T2 > ,          T3 | PromiseLike < T3 > ,          T4 | PromiseLike < T4 > ,          T5 | PromiseLike < T5 > ,          T6 | PromiseLike < T6 > ,          T7 | PromiseLike < T7 > ,      ] , ) : CancellablePromise < [ T1 , T2 , T3 , T4 , T5 , T6 , T7 ] > Type Parameters * T1 * T2 * T3 * T4 * T5 * T6 * T7 Parameters * values : readonly [      T1      | PromiseLike < T1 > ,      T2 | PromiseLike < T2 > ,      T3 | PromiseLike < T3 > ,      T4 | PromiseLike < T4 > ,      T5 | PromiseLike < T5 > ,      T6 | PromiseLike < T6 > ,      T7 | PromiseLike < T7 > , ] Returns CancellablePromise < [ T1 , T2 , T3 , T4 , T5 , T6 , T7 ] > * Defined in example/src/classes/CancellablePromise.ts:247 * all < T1 , T2 , T3 , T4 , T5 , T6 > (      values : readonly [          T1          | PromiseLike < T1 > ,          T2 | PromiseLike < T2 > ,          T3 | PromiseLike < T3 > ,          T4 | PromiseLike < T4 > ,          T5 | PromiseLike < T5 > ,          T6 | PromiseLike < T6 > ,      ] , ) : CancellablePromise < [ T1 , T2 , T3 , T4 , T5 , T6 ] > Type Parameters * T1 * T2 * T3 * T4 * T5 * T6 Parameters * values : readonly [      T1      | PromiseLike < T1 > ,      T2 | PromiseLike < T2 > ,      T3 | PromiseLike < T3 > ,      T4 | PromiseLike < T4 > ,      T5 | PromiseLike < T5 > ,      T6 | PromiseLike < T6 > , ] Returns CancellablePromise < [ T1 , T2 , T3 , T4 , T5 , T6 ] > * Defined in example/src/classes/CancellablePromise.ts:259 * all < T1 , T2 , T3 , T4 , T5 > (      values : readonly [          T1          | PromiseLike < T1 > ,          T2 | PromiseLike < T2 > ,          T3 | PromiseLike < T3 > ,          T4 | PromiseLike < T4 > ,          T5 | PromiseLike < T5 > ,      ] , ) : CancellablePromise < [ T1 , T2 , T3 , T4 , T5 ] > Type Parameters * T1 * T2 * T3 * T4 * T5 Parameters * values : readonly [      T1      | PromiseLike < T1 > ,      T2 | PromiseLike < T2 > ,      T3 | PromiseLike < T3 > ,      T4 | PromiseLike < T4 > ,      T5 | PromiseLike < T5 > , ] Returns CancellablePromise < [ T1 , T2 , T3 , T4 , T5 ] > * Defined in example/src/classes/CancellablePromise.ts:270 * all < T1 , T2 , T3 , T4 > (      values : readonly [          T1          | PromiseLike < T1 > ,          T2 | PromiseLike < T2 > ,          T3 | PromiseLike < T3 > ,          T4 | PromiseLike < T4 > ,      ] , ) : CancellablePromise < [ T1 , T2 , T3 , T4 ] > Type Parameters * T1 * T2 * T3 * T4 Parameters * values : readonly [      T1      | PromiseLike < T1 > ,      T2 | PromiseLike < T2 > ,      T3 | PromiseLike < T3 > ,      T4 | PromiseLike < T4 > , ] Returns CancellablePromise < [ T1 , T2 , T3 , T4 ] > * Defined in example/src/classes/CancellablePromise.ts:280 * all < T1 , T2 , T3 > (      values : readonly [          T1          | PromiseLike < T1 > ,          T2 | PromiseLike < T2 > ,          T3 | PromiseLike < T3 > ,      ] , ) : CancellablePromise < [ T1 , T2 , T3 ] > Type Parameters * T1 * T2 * T3 Parameters * values : readonly [ T1 | PromiseLike < T1 > , T2 | PromiseLike < T2 > , T3 | PromiseLike < T3 > ] Returns CancellablePromise < [ T1 , T2 , T3 ] > * Defined in example/src/classes/CancellablePromise.ts:289 * all < T1 , T2 > (      values : readonly [ T1 | PromiseLike < T1 > , T2 | PromiseLike < T2 > ] , ) : CancellablePromise < [ T1 , T2 ] > Type Parameters * T1 * T2 Parameters * values : readonly [ T1 | PromiseLike < T1 > , T2 | PromiseLike < T2 > ] Returns CancellablePromise < [ T1 , T2 ] > * Defined in example/src/classes/CancellablePromise.ts:297 * all < T > ( values : readonly ( T | PromiseLike < T > ) [] ) : CancellablePromise < T [] > Type Parameters * T Parameters * values : readonly ( T | PromiseLike < T > ) [] Returns CancellablePromise < T [] > * Defined in example/src/classes/CancellablePromise.ts:301 Static all Settled * allSettled < T extends readonly unknown [] | readonly [ unknown ] > (      values : T , ) : CancellablePromise <      {          - readonly [ P in string          | number          | symbol ] : PromiseSettledResult < T [ P ] extends PromiseLike < U > ? U : T [ P ] >      } , > Creates a CancellablePromise that is resolved with an array of results when all of the provided Promises resolve or reject. Type Parameters * T extends readonly unknown [] | readonly [ unknown ] Parameters * values : T An array of Promises . Returns CancellablePromise <      {          - readonly [ P in string          | number          | symbol ] : PromiseSettledResult < T [ P ] extends PromiseLike < U > ? U : T [ P ] >      } , > A new CancellablePromise . * Defined in example/src/classes/CancellablePromise.ts:327 * allSettled < T > (      values : Iterable < T > , ) : CancellablePromise <      PromiseSettledResult < T extends PromiseLike < U > ? U : T > [] , > Creates a CancellablePromise that is resolved with an array of results when all of the provided Promise s resolve or reject. Type Parameters * T Parameters * values : Iterable < T > An array of Promise s. Returns CancellablePromise < PromiseSettledResult < T extends PromiseLike < U > ? U : T > [] > A new CancellablePromise . Canceling it cancels all of the input promises. * Defined in example/src/classes/CancellablePromise.ts:345 Static race * race < T > ( values : readonly T [] ) : CancellablePromise < Awaited < T > > Creates a CancellablePromise that is resolved or rejected when any of the provided Promises are resolved or rejected. Type Parameters * T Parameters * values : readonly T [] An array of Promises . Returns CancellablePromise < Awaited < T > > A new CancellablePromise . Canceling it cancels all of the input promises. * Defined in example/src/classes/CancellablePromise.ts:370 Static delay * delay ( ms : number ) : CancellablePromise < void > Parameters * ms : number Returns CancellablePromise < void > a CancellablePromise that resolves after ms milliseconds. * Defined in example/src/classes/CancellablePromise.ts:385 Settings Member Visibility * Protected * Inherited * External Theme OS Light Dark On This Page Constructors constructor Properties promise cancel Methods then catch finally resolve reject all all Settled race delay Docs API GitHub TypeDoc Example * Loading... Generated using TypeDoc

Links found on this page

  1. TypeDoc Example [direct]
  2. Docs [direct]
  3. API [direct]
  4. GitHub [direct]
  5. CancellablePromise [direct]
  6. real-cancellable-promise [direct]
  7. example/src/classes/CancellablePromise.ts:52 [direct]
  8. TypeDoc Example [direct]