Skip to content

Commit

Permalink
Allow user specify fn for .pipe which returns something but doesn't p…
Browse files Browse the repository at this point in the history
…rovide
  • Loading branch information
Pedro Kehl authored and pedrokehl committed Mar 5, 2024
1 parent 66f08d7 commit 0111404
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
2 changes: 1 addition & 1 deletion benchmark/subFlow.benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async function runSubflowBenchmark(parentItems: number, childItemsPerParent: num
.reduce({ fn: steps.accumulatorFn, seed: 0, provides: 'count' })

const parentCaminho = from(steps.parentGenerator, { maxItemsFlowing: 1_000 })
.pipe({ fn: steps.pipeFn, provides: 'pipe1' })
.pipe({ fn: steps.pipeFn })
.pipe({ fn: (bag: ValueBag) => childCaminho.run(bag, ['count']), provides: 'child' })
.reduce({
fn: (acc: number, bag: ValueBag) => acc + bag.child.count,
Expand Down
8 changes: 3 additions & 5 deletions src/operators/batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ interface BaseBatchParams {
timeoutMs: number
}
maxConcurrency?: number
}
export interface BatchParamsProvides extends BaseBatchParams {
fn: (valueBag: ValueBag[]) => unknown[] | Promise<unknown[]>
provides: string
}

export interface BatchParamsNoProvides extends BaseBatchParams {
fn: (valueBag: ValueBag[]) => void | Promise<void>
export type BatchParamsNoProvides = BaseBatchParams
export interface BatchParamsProvides extends BaseBatchParams {
provides: string
}

export function batch(params: BatchParams, loggers: Loggers): OperatorApplier {
Expand Down
7 changes: 2 additions & 5 deletions src/operators/pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@ export type PipeParams = PipeParamsProvides | PipeParamsNoProvides
interface BasePipeParams {
name?: string
maxConcurrency?: number
fn: (valueBag: ValueBag) => unknown | Promise<unknown>
}

export type PipeParamsNoProvides = BasePipeParams
export interface PipeParamsProvides extends BasePipeParams {
fn: (valueBag: ValueBag) => unknown | Promise<unknown>
provides: string
}

export interface PipeParamsNoProvides extends BasePipeParams {
fn: (valueBag: ValueBag) => void | Promise<void>
}

export function pipe(params: PipeParams, loggers: Loggers): OperatorApplier {
const getBag = pipeHasProvides(params) ? valueBagGetterProvides(params.provides) : valueBagGetterNoProvides()

Expand Down

0 comments on commit 0111404

Please sign in to comment.