Reuse a Fiber in Ruby

I use EventMachine.open_keyboard in my irc client app that uses rbcurse (ncurses gem), as follows:

Fiber.new do
    EM.open_keyboard(NbKeyboard) do |kb|
        $input = Readline.readline("")
        $buffer << $input
    end
end.resume

This code has to be in a Fiber and catch input in a nonblocking way. After I try to type a second line, ruby throws a "dead fiber" exception. I tried adding loops, but that blocks as well, and changing the fiber into a thread doesn't work with the keyboard module. Other ways I tried block all my threads, one of which is responsible for keeping the buffer updated/refreshed. How can I change the code to keep the Fiber open/alive after typing the first line? To view the keyboard module (didn't write it myself), go here.

Edit: Thanks to the answer of Sawa I figured it out:

Fiber.new do
    EM.open_keyboard(NbKeyboard) do |kb|
        loop do
            $input = Readline.readline("")
            $buffer << $input
            Fiber.yield
        end
    end
 end.resume

Answers


Add

loop{Fiber.yield}

at the end of the fiber body.


Need Your Help

CONCAT rows and return within GROUP

mysql group-by concat

I have the following SQLFiddle, i can group the results by time, count and name, but i also want to return the error_strings within the same row.

Where do I catch and handle maxAllowedContentLength exceeded in IIS7?

iis-7 web-config http-status-code-404 httpapplication

I have an aspx page where I’m allowing a user to upload a file and I want to cap the max file upload size to be 10MB. IIS7, .NET 3.5. I have the following configured in my web.config file: