Skip to main content
Module

x/enzastdlib/async/mod.ts>makePromise

enzastdlib is a set of TypeScript modules that follow a common design API philosophy aiming at sane defaults and ease-of-use targeting the Deno TypeScript runtime.
Latest
function makePromise
import { makePromise } from "https://deno.land/x/enzastdlib@v0.0.4/async/mod.ts";

Returns a Promise instance along with its resolve and reject functions.

Examples

Example 1

import {
    assertEquals,
    assertInstanceOf,
} from 'https://deno.land/std/testing/asserts.ts';
import { makePromise } from 'https://deno.land/x/enzastdlib/async/mod.ts';
import { assertTypeOf } from 'https://deno.land/x/enzastdlib/testing/mod.ts';

const { promise, resolve, reject } = makePromise<number>();

assertInstanceOf(promise, Promise);

assertTypeOf(resolve, 'function');
assertTypeOf(reject, 'function');

resolve(42);

assertEquals(await promise, 42);

Type Parameters

optional
Value = void

Returns

{ promise: Promise<Value>; resolve: (value: Value) => void; reject: (reason?: unknown) => void; }