Ensuring parent fails when forked effect fails

How can I run a child effect in the background but still ensure the parent fails if the child fails? I thought Effect.fork would be my friend, but the below doesn't seem to work this way - it seems to just swallow the failure instead:
import { Console, Duration, Effect, Schedule } from 'effect'

const failingJob = Effect.gen(function* (_) {
  yield* _(Effect.sleep(Duration.seconds(3)))
  console.log('what a nice sleep!')
  yield* _(Effect.fail('oh no'))
})

const otherJob = Effect.repeat(
  Console.log('job still running!'),
  Schedule.fixed('1 seconds'),
)

const program = Effect.gen(function* (_) {
  yield* _(Effect.fork(failingJob))
  yield* _(Effect.fork(otherJob))
  yield* _(Effect.sleep(Duration.infinity))
})

Effect.runPromise(program)

// prints:
// job still running!
// job still running!
// job still running!
// what a nice sleep!
// job still running!
// job still running!
Was this page helpful?