[ruby-core:66441] Re: [ruby-trunk - Bug #10540] [Open] Yielded fibers do not execute ensure blocks

From: Eric Wong <normalperson@...>
Date: 2014-11-24 21:05:30 UTC
List: ruby-core #66441
This seems unfortunate.  I'm not sure if there's a good way to do
this automatically with current APIs because Fibers require
explicit scheduling.

Perhaps storing Fibers in Thread.current and having a
terminate_all_fibers method can be helpful:

Thread.new do
  begin
    do_something_which_creates_fibers
  ensure
    # all thread-local fibers are resumed until they're dead
    terminate_all_fibers
  end
end

In This Thread

Prev Next