Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/fun/promise.ts

A collection of algebraic data types, lenses, and schemables based on a light weight higher kinded type implementation. Written for deno.
Go to Latest
import * as fun from "https://deno.land/x/fun@v.2.0.0-alpha.11/promise.ts";

Variables

The canonical implementation of Applicative for Promise. It contains the methods of, ap, and map.

The canonical implementation of Apply for Promise. It contains the methods ap and map.

The canonical implementation of Chain for Promise. It contains the methods ap, map, and chain.

The canonical implementation of Functor for Promise. It contains the method map.

The canonical implementation of Monad for Promise. It contains the methods of, ap, map, join, and chain.

Functions

Make an existing Promise somewhat abortable. While the returned promise does resolve when the abort signal occurs, the existing promise continues running in the background. For this reason it is important to catch any errors associated with the original promise.

An alias for Promise.all

Create a new Promise from a Promise<(a: A) => I> and a Promise. Although Promises encapsulate asynchrony, there is no way defer a Promise once created, thus this ap function always evaluates both input Promises in parallel.

An alias for Promise.catch

Create a new Promise by chaining over the result of an existing Promise. This is effectively Promise.then.

Create a Deferred from a type.

Delay the resolution of an existing Promise. This does not affect the original promise directly, it only waits for a ms milliseconds before chaining into the original promise.

This function theoretically flattens A Promise<Promise>. However, there is a need for this function in Monad. Since there is no way to actually create the input of this function, there is no example.

Create a new Promise by mapping over the result of an existing Promise. This is effectively Promise.then, but narrowed to non-promise returning functions. If the mapping function returns a Promise then the type for this function will be incorrect, as there is no way to create a Promise<Promise>.

Create a Promise from a value A or another PromiseLike. This is essentially an alias of Promise.resolve.

An alias for Promise.race. Note that Promise.race leaks async operations in most runtimes. This means that the slower promise does not stop when the faster promise resolves/rejects. In effect Promise.race does not handle cancellation.

An alias for Promise.reject.

An alias for Promise.resolve.

An alias for Promise.then

Wrap a function that potentially throws in a try/catch block, handling any thrown errors and returning the result inside of a Promise.

Create a Promise that resolve after ms milliseconds.

Interfaces

Specifies Promise as a Higher Kinded Type, with covariant parameter A corresponding to the 0th index of any Substitutions.

Type Aliases

A type for Promise over any, useful as an extension target for functions that take any Promise and do not need to extract the type.

A Promise with the inner resolve function hoisted and attached to itself.

A type level extractor, used to pull the inner type from a Promise.