@motorcycle/test
Version:
Testing functions for Motorcycle.ts
19 lines (15 loc) • 528 B
text/typescript
import { Stream } from '@motorcycle/types'
import { until } from '@motorcycle/stream'
export function createDisposableSinks<Sinks extends Readonly<Record<string, Stream<any>>>>(
sinks: Sinks,
endSignal: Stream<any>
): Sinks {
return Object.keys(sinks).reduce<Sinks>(function createDisposableSink(
disposableSinks: Sinks,
sinkName: keyof Sinks
): Sinks {
const disposableSink = until(endSignal, sinks[sinkName])
disposableSinks[sinkName] = disposableSink
return disposableSinks
}, {} as Sinks)
}