import * as G from './GeneratorUtils';
import { Signal } from './Signal';
export type PipelineTransform<InType = any, OutType = any> = (src: AsyncGenerator<InType>) => AsyncGenerator<OutType>;
type AsyncGeneratorWithId<T> = AsyncGenerator<T> & {
    id: string;
};
/**
 * Pipeline public interface
 */
export type IPipeline<InType, OutType = InType> = {
    pipe<NewOutType>(fn: PipelineTransform<OutType, NewOutType>): IPipeline<InType, NewOutType>;
    filter(fn: G.GeneratorFilter<OutType>): IPipeline<InType, OutType>;
} & AsyncGenerator<OutType>;
declare class PipelineDefinition<InType, OutType = InType> {
    source: AsyncGeneratorWithId<InType>;
    protected transforms: PipelineTransform[];
    constructor(source: AsyncGenerator<InType>, transforms?: PipelineTransform[]);
    /**
     * Append a transformation step to this pipeline.
     * Changes the pipeline's output type to output type of this generator.
     */
    pipe<NewOutType>(fn: PipelineTransform<OutType, NewOutType>): PipelineDefinition<InType, NewOutType>;
    clearTransforms(): void;
    setSource(source: AsyncGenerator<InType> | AsyncGeneratorWithId<InType>): AsyncGeneratorWithId<InType>;
    getTransforms(): PipelineTransform<any, any>[];
}
export declare class Pipeline<InType, OutType = InType> implements IPipeline<InType, OutType> {
    source: AsyncGenerator<InType>;
    protected iterator: AsyncGenerator<OutType>;
    private isIterating;
    isCleaningUp: boolean;
    private definition;
    constructor(source: AsyncGenerator<InType>, definition?: PipelineDefinition<InType, OutType>);
    /**
     * Append a transformation step to this pipeline.
     * Changes the pipeline's output type to output type of this generator.
     */
    pipe<NewOutType>(fn: PipelineTransform<OutType, NewOutType>): Pipeline<InType, NewOutType>;
    /**
     * Triggers once when pipeline ends.
     * Usage: `pipeline.onFinally(callback)`
     */
    onFinally: Signal<[Error | undefined]>;
    /**
     * Triggers once when pipeline is about to end.
     */
    onBeforeFinally: Signal<[]>;
    onMessage: Signal<[OutType]>;
    onError: Signal<[Error, (InType | OutType | undefined)?, (number | undefined)?]>;
    filter(fn: G.GeneratorFilter<OutType>): Pipeline<InType, OutType>;
    flow(): this;
    private cleanup;
    handleError(err: Error): Promise<void>;
    private iterate;
    throw(err: Error): Promise<IteratorResult<OutType, any>>;
    return(v?: OutType): Promise<IteratorResult<OutType, any>>;
    next(): Promise<IteratorResult<OutType, any>>;
    /**
     * Create a new Pipeline forked from this pipeline.
     * Pushes results into fork.
     * Note: Does not start consuming this pipeline.
     */
    [Symbol.asyncIterator](): this;
}
export {};
