Managing a Background Process Lifecycle with Parent Process

How would I run a a background process for the duration that a parent process is running? In pseudocode:

const myStream = pipe(
  mySetupEffect,
  Effect.tap(setupResult => startBackgroundProcess(setupResult)),
  Effect.fromStream,
  Stream.flatMap(setupResult => pipe(
    Stream.succeed(setupResult),
    Stream.concat(streamTheData(setupResult))
  ))
)


And now I'd want for the Effect returned from startBackgroundProcess to run continuously for as long as myStream is being consumed, and to stop (via an interrupt) when myStream is interrupted or completes.
Was this page helpful?