import { type Bind, type Kind2, type TypeLambda } from 'sts:hkt';
import { Failure } from 'sts:failures';
import { type Result } from 'sts:result';
import { type Applicative, type AsyncMonad, type Functor, type Monad } from 'sts:typeclasses';
export interface AbortSignalLike {
    readonly aborted: boolean;
    readonly reason?: unknown;
    // #[effects(add: [], unknown: [direct])]
    addEventListener(type: 'abort', listener: () => void, options?: boolean | {
        once?: boolean;
    }): void;
    // #[effects(add: [], unknown: [direct])]
    removeEventListener(type: 'abort', listener: () => void, options?: boolean): void;
}
export type Task<T, E = Error> = (signal?: AbortSignalLike) => Promise<Result<T, E>>;
export interface TaskF extends TypeLambda {
    readonly type: Task<this['Args'][1], this['Args'][0]>;
}
export interface PromiseF extends TypeLambda {
    readonly type: Promise<this['Args'][0]>;
}
export type TaskKind<E, T> = Kind2<TaskF, E, T>;
export type PromiseKind<T> = Promise<T>;
export declare class TimeoutFailure extends Failure {
    readonly ms: number;
    // #[effects(add: [mut])]
    constructor(ms: number, cause?: unknown);
}
// #[effects(add: [])]
export declare function succeed<T>(value: T): Task<T, never>;
// #[effects(add: [])]
export declare function fail<E>(error: E): Task<never, E>;
// #[effects(add: [])]
export declare function fromResult<T, E>(result: Result<T, E>): Task<T, E>;
// #[effects(add: [])]
export declare function fromPromise<T>(fn: (signal?: AbortSignalLike) => Promise<T>): Task<T, Error>;
// #[effects(add: [])]
export declare function fromPromise<T, E>(fn: (signal?: AbortSignalLike) => Promise<T>, mapError: (error: Error) => E): Task<T, E>;
// #[effects(add: [])]
export declare function map<A, B, E>(task: Task<A, E>, project: (value: A) => B): Task<B, E>;
// #[effects(add: [])]
export declare function mapError<A, E1, E2>(task: Task<A, E1>, project: (error: E1) => E2): Task<A, E2 | Error>;
// #[effects(add: [])]
export declare function flatMap<A, B, E1, E2>(task: Task<A, E1>, project: (value: A) => Task<B, E2>): Task<B, E1 | E2>;
// #[effects(add: [])]
export declare function recover<A, B, E>(task: Task<A, E>, project: (error: E) => B | Promise<B>): Task<A | B, Error>;
// #[effects(add: [])]
export declare function tap<A, E>(task: Task<A, E>, effect: (value: A) => unknown | Promise<unknown>): Task<A, E | Error>;
// #[effects(add: [])]
export declare function tapError<A, E>(task: Task<A, E>, effect: (error: E) => unknown | Promise<unknown>): Task<A, E | Error>;
// #[effects(add: [])]
export declare function parallel<T, E>(tasks: readonly Task<T, E>[]): Task<readonly T[], E>;
// #[effects(add: [])]
export declare function race<T, E>(tasks: readonly [
    Task<T, E>,
    ...Task<T, E>[]
]): Task<T, E>;
// #[effects(add: [])]
export declare function timeout<T, E>(task: Task<T, E>, ms: number): Task<T, E | TimeoutFailure>;
// #[effects(add: [])]
export declare function taskFunctor<E>(): Functor<Bind<TaskF, [
    E
]>>;
// #[effects(add: [])]
export declare function taskApplicative<E>(): Applicative<Bind<TaskF, [
    E
]>>;
// #[effects(add: [])]
export declare function taskMonad<E>(): Monad<Bind<TaskF, [
    E
]>>;
// #[effects(add: [])]
export declare function taskAsyncMonad<E>(): AsyncMonad<Bind<TaskF, [
    E
]>>;
export declare const promiseFunctor: Functor<PromiseF>;
export declare const promiseApplicative: Applicative<PromiseF>;
export declare const promiseMonad: Monad<PromiseF>;
export declare const promiseAsyncMonad: AsyncMonad<PromiseF>;
