/** * Drains the provided stream in the background for as long as this stream is * running. If this stream ends before `other`, `other` will be interrupted. * If `other` fails, this stream will fail with that error. * * @tsplus static effect/core/stream/Stream.Aspects drainFork * @tsplus pipeable effect/core/stream/Stream drainFork */ export function drainFork(other: Stream) { return (self: Stream): Stream => Stream.fromEffect(Deferred.make()).flatMap( (backgroundDied) => Stream.scoped( other .runForEachScoped(() => Effect.unit) .catchAllCause((cause) => backgroundDied.failCause(cause)) .forkScoped ).crossRight(self.interruptWhenDeferred(backgroundDied)) ) }