Replies: 2 comments 1 reply
-
I would still say that
Even if the fiber is finite and short-lived, it may acquire resources or have some finalizers. If the application (gracefully) shuts down, those finalizers will not be run. In general, you should prefer
A fiber can self cancel via
Depends what "unexpectedly" means exactly :) no, a fiber will not spontaneously
Note, the only fiber that is directly canceled by
No, I would say that's not correct. The benefit is that the finalizers of those fibers (e.g. flushing files, releasing resources, gracefully closing connections) are guaranteed to be called when the app shuts down. If you just use |
Beta Was this translation helpful? Give feedback.
-
Adding a more succinct follow-on to @armanbilge's excellent answer…
However, inventing novel forms of concurrency is not something most end users need to worry about! Instead of doing this, tools like |
Beta Was this translation helpful? Give feedback.
-
Hi 👋, I have 3 questions about fibers and cancellation in cats effect:
The Scala docs on
.start
say that it is an unsafe combinator wrt cancellation. If cancellation is not a concern (for instance if the started fiber does work that is finite, i.e. it won't run forever and perhaps shortlived or if I keep a handle on the fiber making sure to cancel it when needed) is it correct to say that.start
is not unsafe ? Or in other words in what situations is it acceptable to call.start
?Besides manually calling
.cancel
on a fiber and using structured concurrency combinators such as.race
,.parMap
, etc... and perhaps SIGTERM | SIGINT (or whatever system message is used for graceful shutdown), what else can cause a fiber to be cancelled ? Trying to understand if cancellation is something that can happen unexpectedly.If the purpose of the
Supervisor
is to tie the lifecycle of a fiber to the supervisor's lifecycle, is it correct to say that if the latter extends to the lifecycle of the entire app (as it's usually the case forResources
in cats effect applications) then there's not much benefit from using it besides perhaps being able to control the termination policy (await = true | false
) ? What would help me understand here is a clear use case where using a supervisor makes a clear difference to the application logic.Thank you.
Beta Was this translation helpful? Give feedback.
All reactions