Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tutorial] Timeout
#1
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.
Reply
#2
First comment.
Thank's for the share man Oui
[Image: logo.png]
xSexy.org | The New Sexy Forum ! [Erotic Pics & Videos]
Reply
#3
I don't use Ruby but thanks, I have learn but the little bit of code Smile
Reply
#4
Nice share Thanks
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)