import type { AsyncExit } from "./AsyncExit"; import type { Async } from "./model"; import { DoneInstruction, FailInstruction, PartialInstruction, PromiseInstruction, SucceedInstruction, SuspendInstruction, TotalInstruction } from "./model"; /* * ------------------------------------------- * Async Constructors * ------------------------------------------- */ export const succeed = (a: A): Async => new SucceedInstruction(a); export const fail = (e: E): Async => new FailInstruction(e); export const done = (exit: AsyncExit): Async => new DoneInstruction(exit); export const suspend = (factory: () => Async): Async => new SuspendInstruction(factory); export const unfailable = ( promise: (onInterrupt: (f: () => void) => void) => Promise ): Async => new PromiseInstruction(promise, () => undefined as never); export const promise_ = ( promise: (onInterrupt: (f: () => void) => void) => Promise, onError: (u: unknown) => E ): Async => new PromiseInstruction(promise, onError); export const promise = (onError: (u: unknown) => E) => ( promise: (onInterrupt: (f: () => void) => void) => Promise ) => new PromiseInstruction(promise, onError); export const total = (thunk: () => A): Async => new TotalInstruction(thunk); export const partial_ = (thunk: () => A, onThrow: (error: unknown) => E): Async => new PartialInstruction(thunk, onThrow); export const partial = (onThrow: (error: unknown) => E) => (thunk: () => A): Async => partial_(thunk, onThrow);