Support Forums
[Tutorial] Timeout - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Ruby and Ruby on Rails (https://www.supportforums.net/forumdisplay.php?fid=55)
+---- Thread: [Tutorial] Timeout (/showthread.php?tid=5728)



[Tutorial] Timeout - Wolskie - 04-06-2010

Ruby has a very nice timeout library, that can be uses in many different places including network application to applications that have time limits, for example a chess game. This is a short example on how to use the library.

Example code:
Code:
require('timeout')
begin
  Timeout::timeout(5) do
    $stdout.puts("Give me an answer.")
    a = gets
    $stdout.puts("Your answer is #{a}")
  end
rescue TimeoutError
  $stdout.puts("\n**You took to long**")
end

If you enter an answer before the 5 second timeout you will receive a message
saying "You answer was" plus you answer.

If you took longer than the time, it prints "** You took too long**"

This is a basic example on how to use the timeout library.


RE: [Tutorial] Timeout - JesusOfSuburbia - 05-03-2010

First comment.
Thank's for the share man Oui


RE: [Tutorial] Timeout - Julie - 05-09-2010

I don't use Ruby but thanks, I have learn but the little bit of code Smile


RE: [Tutorial] Timeout - Bursihido - 12-13-2010

Nice share Thanks