cats-effect
cats-effect copied to clipboard
Add `GenConcurrent#forceStart` that guarantees a fiber will start
The possibility of an uncancelable fiber being canceled before it starts executing is, I think, a surprising footgun for many people. If nothing else, adding this forceStart method will help raise awareness of that possibility.
The test failure doesn't appear to be related to the contents of this PR:
[info] WorkerThreadNameSpec
[info] WorkerThread should
[error] x rename itself when entering and exiting blocking region
[error] the value is false (WorkerThreadNameSpec.scala:73)
I'm kind of on the fence about this one, conceptually. Fibers are, fundamentally, three state objects: unstarted, started, and completed. Cancelation has different effects depending on which state the fiber is in (atomically), and this is just fundamental in the model. What this PR does is attempt to eliminate the first state from the calculus by blocking cancel until the fiber moves into the second state. This does work but it raises a lot of other questions around what you should do if the requisite blocking starts to become noticeably long. In other words, it's still a footgun, just of a different sort.