Feature #17325

Updated by nevans (Nicholas Evans) over 1 year ago

This skips rescue and catch blocks but runs all ensure blocks. It can be run on any living fiber, and propagates cancellation to child (resumed) fibers. 

 Basically, I want it to behave as if you called `break` or `return` to jump all the way to the top frame of the fiber from wherever it is.. Exceptions might be too heavy-weight, can't (and shouldn't) be sent to resuming fibers, and can be caught. This can also be emulated via `catch/throw` with an anonymous ``, but that adds an extra stack frame, and implementing it reliably requires interception of `Fiber.yield`, e.g. adding a `Fiber.throw` (analogous to `Fiber.raise`) which also shouldn't be sent to resuming fibers. 

 I tried to match the new _(much improved!)_ transfer/resume switch semantics with cancel propagation. When the cancellation propagates all the way to the bottom of the fiber resume stack, the last fiber in the chain will then be resumed. Resuming fibers will not run until they are yielded back into. 

 If called I think it's important to allow future `resume` and `transfer` out of a canceled fiber, in case it's necessary to close resources from `ensure` blocks. However, may have chosen the wrong behavior for multiple times, each `cancel` will propagate cancellation `cancels` on a `canceling`. I chose to use the same propagate/resume/transfer semantics but _not `break` again_ after subsequent cancels. On second thought, I think it should behave more like a standard `break`, and behave as if do exactly the same thing that `break` or `return` was called. would normally do if they are called from an `ensure` block. I'll update this patch with that behavior when I'm able to.