cats-effect icon indicating copy to clipboard operation
cats-effect copied to clipboard

"`ResourceSupervisor`"

Open armanbilge opened this issue 2 years ago • 2 comments

This is an idea @TimWSpence and I cooked up once on Discord, starting from https://github.com/typelevel/fs2/pull/2300#issuecomment-1325010963.

The idea is very similar to the existing Supervisor which allows to start a fiber, and bind its lifecycle to some outer scope. Here, we want to allocate a Resource and bind its lifecycle to the outer scope.

ResourceSupervisor[F].use { supervisor =>
  resourceA.allocateSupervised(supervisor).flatMap { (a, release) =>
    // do stuff
  }
}

allocateSupervised (or superviseAllocated ?) would work like allocated, except in case the release is not invoked for some reason, it will be cleaned up once the supervisor scope ends.

tl;dr start is to allocated what supervise is to (we need something here :)

armanbilge avatar Jan 18 '23 17:01 armanbilge

Some overlap with:

  • https://github.com/typelevel/cats-effect/issues/1345

armanbilge avatar Mar 03 '23 23:03 armanbilge