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

Fork-with-finalizer method on `GenSpawn`

Open durban opened this issue 2 months ago • 0 comments

(Based on this comment by @TomasMikula; I'm opening a new issue, because approximately nobody reads closed issues.)

The idea is to have a new method on GenSpawn like this (name TBD):

def forkWithFinalizer[A](fa: F[A], fin: F[Unit]): F[Fiber[F, A]]

It would be different from start in that if this method returned a fiber, then fin would be guaranteed to be executed (except of course if fa hangs). There is no such gurarantee with start.

A new method on GenSpawn would require a default implementation. A possibility is in #4500.

Open questions:

  • Do we actually want something like this on the public API?
  • Are we okay with the default implementation? (I think it works, but I've been wrong before.)
  • What to name the method?

durban avatar Oct 21 '25 22:10 durban