Skip to main content
The Deno 2 Release Candidate is here
Learn more
Module

x/grm/deps.ts>CancellablePromise#then

MTProto API Client for Deno 🦕
Go to Latest
method CancellablePromise.prototype.then
Re-export
import { CancellablePromise } from "https://deno.land/x/grm@0.8.0/deps.ts";

Analogous to Promise.then.

onFulfilled on onRejected can return a value, a normal promise, or a CancellablePromise. So you can make a chain a CancellablePromises like this:

const overallPromise = cancellableAsyncFunction1()
    .then(cancellableAsyncFunction2)
    .then(cancellableAsyncFunction3)
    .then(cancellableAsyncFunction4)

Then if you call overallPromise.cancel, cancel is called on all CancellablePromises in the chain! In practice, this means that whichever async operation is in progress will be canceled.

Type Parameters

optional
TResult1 = T
optional
TResult2 = never

Parameters

optional
onFulfilled: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null
optional
onRejected: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null

Returns

a new CancellablePromise