There is a Ruby class Timeout that terminates the execution of a block after a certain amount of seconds:
Timeout.timeout(5) {
# Some long-running code...
}
The problem is that every time I call timeout() it starts a new Thread. It's pretty expensive (time and memory) operation. Would be much more effective to re-use an existing thread. Are there any Gems for that?