cats-effect
cats-effect copied to clipboard
"`ResourceSupervisor`"
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 :)
Some overlap with:
- https://github.com/typelevel/cats-effect/issues/1345