import type { Deferred } from "../util/async.js";
import type { Nullable } from "../util/null.js";
import { Sequence } from "./Sequence.js";
export type DeferredErrorResult = {
    readonly reason: unknown;
};
export type DeferredResult<T, R> = IteratorResult<T, R | undefined> | DeferredErrorResult;
/**
 * Deferred sequence of values that can be async iterated and new values can be published.
 * - Implements `Deferred` so the next result can be set.
 * - Implements `Promise` so the next result can be awaited.
 * - Implements `AsyncIterable` so values can be iterated over using `for await...of`
 * - Call `resolve(value)` to publish the next value, `reject(reason?)` to publish an error, or `done(value?)` to signal completion.
 */
export declare class DeferredSequence<T = void, R = void, N = void> extends Sequence<T, R, N> implements Deferred<T>, Promise<T> {
    /** Lazy deferred that stores iterator values. */
    private _iteratorDeferred;
    /** Lazy deferred that stores promise values. */
    private _promiseDeferred;
    /** Next iterator result to reject the deferred to (on next microtask). */
    private _next;
    /** Get the next promise to be resolved/rejected. */
    get promise(): Promise<T>;
    /**
     * Resolve the current deferred in the sequence with a value.
     * - Sends a `{ value: X }` to any iterators.
     */
    resolve(value: T): void;
    /**
     * Reject the current deferred in the sequence.
     */
    reject(reason: unknown): void;
    /**
     * Signal that the sequence is done, causing any active `for await` loops to exit cleanly.
     * - Sends a `{ done: true, value: R }` to any iterators.
     */
    done(value?: R | undefined): void;
    /**
     * Cancel the current resolution or rejection.
     * - Iterators will contain to wait for a next value.
     */
    cancel(): void;
    /** Fulfill the current deferred by resolving or rejecting both the iterator deferred and the promise deferred. */
    private _fulfill;
    /** Resolve the current deferred from a sequence of values. */
    through(sequence: AsyncIterable<T>): AsyncIterator<T>;
    next(_next?: N | undefined): Promise<IteratorResult<T, R | undefined>>;
    then<X = T, Y = never>(onNext?: Nullable<(v: T) => X | PromiseLike<X>>, onError?: Nullable<(r: unknown) => Y | PromiseLike<Y>>): Promise<X | Y>;
    catch<Y>(onError: (r: unknown) => Y | PromiseLike<Y>): Promise<T | Y>;
    finally(onFinally: () => void): Promise<T>;
    [Symbol.asyncDispose](): Promise<void>;
}
