suspenders-js
Version:
Asynchronous programming library utilizing coroutines, functional reactive programming and structured concurrency.
35 lines (34 loc) • 1.22 kB
TypeScript
import { Suspender } from "./Types";
/**
* Starts the suspender but doesn't wait for it's result. Returns a new suspender that returns the
* result.
* @param {Suspender<T>} suspender
* @return {Suspender<T>}
*/
export declare const async: <T>(suspender: Suspender<T>) => Suspender<T>;
/**
* Returns the first suspender to resolve successfully. All other pending suspenders are canceled.
* If all suspenders error, throws the last error.
* @params {Array<Suspender<T>>} suspenders
* @return {Suspender<T>}
*/
export declare const race: <T>(...suspenders: Suspender<T>[]) => Suspender<T>;
/**
* Returns a suspender that resolves with given timout.
* @param {number} millis
* @return {Suspender<void>}
*/
export declare const wait: (millis: number) => Suspender<void>;
export declare const awaitCancelation: () => Suspender<void>;
/**
* Converts a Promise<T> to a Suspender<T>.
* @param {Promise<T>} promise
* @return {Suspender<T>}
*/
export declare const promiseSuspender: <T>(promise: Promise<T>) => Suspender<T>;
/**
* Performs an http get on url. Returns body on 200 or throws error.
* @param {string} url
* @return {Suspender<T>}
*/
export declare const httpGet: (url: string) => Suspender<string>;