gsamokovarov/web-console — pull request #11 by gsamokovarov (2013-07-26 13:06:31+00:00)
Title: Add failing mutliline support between threads test

Something that I have overlooked when I [started with the fibers][commit], as a means to simulate user input, is that they cannot be resumed across threads.

The issue we recently run into is that the default development server (WEBrick) can allocate a request to a thread that did not created the `ConsoleSession`, hence the underlying `WebConsole::REPL::IRB` instance. This causes any call to `WebConsole::REPL::IRB#send_input` to fail with `FiberError: fiber called across threads`.

To work around that, I introduced a [hack][] which, while pretty ugly, made the console usable enough for a demo. However e pretty simple case may break it. That is, switching the thread, while still in a multiline session.

I am introducing a failing test for it and I'm getting into a hunt for a solution. I have two ideas for a fix:

1. Find a way to support multiline sessions without fibers. If we eliminate the needs of the fibers and we are able to trick IRB, we would be done. As of now, all of my attempts to remedy this have failed.

2. Allocate a consumer thread for every `WebConsole::REPL::IRB` instance, in which the fiber will live in. On every `WebConsole::REPL::IRB#send_input` we would put the input into a queue that the thread will listen to. The difficult part would be to get the output out of the producer thread. The other thing is that we have to be 1 bit more extra careful, since we would introduce a lot threads into the system and if we don't managed them well, problems lot a of we run may.

I'm putting this one aside now, since it rarely happened to me in a browser session. For my two days of testing, I have runned into this just once, so I don't see a reason for us to delay our demo/preview 0.1 release, which me and @guilleiguaran have planned to get out in the beginning of the next week.

However, this should be the top priority to fix after we release the demo. Nobody would like to loose a long class or module definition.

[commit]: aef07e4c9593c9957a02cfb91ae0bb1507cce70
[hack]: baa6984ef4fa402b9977f5cc01d16b9240db7795