how to put timer on ruby

Discussion in 'Ruby' started by griffith Khana, Dec 16, 2009.

  1. i need a timer for the program i am writing but i don't know the code so
    please someone help me to write timer.......
    thanx for your help...
    --
    Posted via http://www.ruby-forum.com/.
     
    griffith Khana, Dec 16, 2009
    #1
    1. Advertising

  2. griffith Khana

    bwv549 Guest

    bwv549, Dec 16, 2009
    #2
    1. Advertising

  3. > i need a timer for the program i am writing but i don't know the code so
    > please someone help me to write timer.......
    > thanx for your help...


    a) timeout:

    require 'timeout'
    timeout(4) do
    # code in here will only run for 4 seconds
    end

    If you look at the implementation of timeout, you will see that it is
    easy to time code using Kernel.sleep. This is however very imprecise and
    can't be used for animation loops, for example.

    b) EventMachine

    require 'eventmachine'
    time = Time.now
    EventMachine::add_timer(1) do
    puts "hello one second from #{time}!"
    end

    Eventmachine should allow you to do more precise timing. Your
    possibilities are of course limited by the system you run on.

    greetings,
    kaspar
     
    Kaspar Schiess, Dec 17, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kelsang Wangchuk

    System.Timers.Timer vs. System.Threading.Timer

    Kelsang Wangchuk, Jul 31, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    760
    Kelsang Wangchuk
    Jul 31, 2003
  2. Replies:
    1
    Views:
    1,685
    Steve C. Orr [MVP, MCSD]
    Feb 22, 2005
  3. Simon

    page timer, or redirect timer

    Simon, Nov 4, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    11,267
    Bruce Barker
    Nov 4, 2005
  4. C Learner

    Put a Timer on the web form

    C Learner, Aug 10, 2004, in forum: ASP General
    Replies:
    1
    Views:
    119
    Evertjan.
    Aug 10, 2004
  5. Replies:
    8
    Views:
    637
    Jorgen Grahn
    Jul 15, 2013
Loading...

Share This Page