:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
import { ChunkPipeline, ChunkPipelineResultWithContext, OkResultWithContext } from './chunk-pipeline.interface'
import { Pipeline, PipelineResultWithContext } from './pipeline.interface'
import { isOkResult } from './results'
export class SequentialChunkPipeline<
TInput,
TIntermediate,
TOutput,
CInput,
COutput = CInput,
RPrev extends string = never,
RStep extends string = never,
> implements ChunkPipeline<TInput, TOutput, CInput, COutput, RPrev | RStep>
{
constructor(
private currentPipeline: Pipeline<TIntermediate, TOutput, COutput, RStep>,
private previousPipeline: ChunkPipeline<TInput, TIntermediate, CInput, COutput, RPrev>
) {}
feed(elements: OkResultWithContext<TInput, CInput>[]): void {
this.previousPipeline.feed(elements)
}
async next(): Promise<ChunkPipelineResultWithContext<TOutput, COutput, RPrev | RStep> | null> {
const previousResults = await this.previousPipeline.next()
if (previousResults === null) {
return null
}
const results: PipelineResultWithContext<TOutput, COutput, RPrev | RStep>[] = []
for (const resultWithContext of previousResults) {
if (isOkResult(resultWithContext.result)) {
const pipelineResult = await this.currentPipeline.process({
result: resultWithContext.result,
context: resultWithContext.context,
})
results.push(pipelineResult)
} else {
results.push({
result: resultWithContext.result,
context: resultWithContext.context,
})
}
}
return results
}
}