cats-effect
cats-effect copied to clipboard
Added fiber restart functionality to `Supervisor`
Needs documentation and stuff. This adds support for configurable supervised restarts, similar to how supervisor nets work in Erlang. The idea is basically that you can configure a supervision predicate which optionally restarts a supervised fiber when it completes in a certain way. Due to type constraints, it is impossible to case on the value being returned when it is successful, but I think this is fine.
Thoughts welcome.
So question about this: is it possible to implement this as new method on Supervisor?
The bincompat constraint makes it slightly ugly, and I guess the default implementation wouldn't even need to delegate to supervise 🤔 unless there's a dumbed down default implementation in terms of Monad or something.
But on the other hand, I think the API would be more flexible: a single Supervisor could be used for restarting and non-restarting fibers and also checkRestart would be able to introspect the A.
def supervisedRestart[A](fa: F[A])(
checkRestart: Outcome[F, Throwable, A] => Boolean
)(implicit F: Concurrent[F]): F[Fiber[F, Throwable, A]]
So question about this: is it possible to implement this as new method on Supervisor?
Okay this is very smart and I agree it's much better. It allows users to think about Supervisor in terms of its lifecycle scope, while restart semantics are on a per-fiber basis. Still doesn't allow people to inspect the A because it is wrapped in F, but the types are simpler and we avoid the existential.