vulpix
Version:
CSP-like channels library
18 lines (17 loc) • 1.02 kB
TypeScript
import { Result } from '../result';
/**
* Asynchronous Result wrapper which is equivalent to Result<T, E> but for async computations.
* Replaces the use of Promise<Result<T, E>> and hides some Promise methods such as `catch` and `finally`
* because it will always resolve.
*/
declare class AsyncResult<T, E extends Error = Error> implements PromiseLike<Result<T, E>> {
private readonly promiseLike;
private constructor();
then<TResult1 = Result<T, E>, TResult2 = never>(onfulfilled?: ((value: Result<T, E>) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null | undefined): PromiseLike<TResult1 | TResult2>;
toPromise(): Promise<Result<T, E>>;
static ok(): AsyncResult<void>;
static ok<T>(value: T): AsyncResult<T>;
static error<E extends Error>(error: E): AsyncResult<never, E>;
static of<T, E extends Error = Error>(promiseLike: PromiseLike<Result<T, E>>): AsyncResult<T, E>;
}
export { AsyncResult };