Pausable script

Discussion in 'Ruby' started by Ted Flethuseo, Oct 25, 2010.

  1. Hi everyone,

    I'm trying to build a script that writes something every 2 minutes. This
    is what I have so far, but I would like to make it so that I can pause
    it, with a certain key, and make it continue with another key. When it
    is unpaused it should keep track where it left off.

    Any ideas how to do this?

    40.times do |i|
    puts i
    sleep(200);
    puts "write something"
    end

    Ted

    --
    Posted via http://www.ruby-forum.com/.
     
    Ted Flethuseo, Oct 25, 2010
    #1
    1. Advertising

  2. On Mon, Oct 25, 2010 at 3:26 PM, Ted Flethuseo <> wrote:
    > Hi everyone,
    >
    > I'm trying to build a script that writes something every 2 minutes. This
    > is what I have so far, but I would like to make it so that I can pause
    > it, with a certain key, and make it continue with another key. When it
    > is unpaused it should keep track where it left off.
    >
    > Any ideas how to do this?
    >
    > 40.times do |i|
    > =A0 =A0puts =A0i
    > =A0 =A0sleep(200);
    > =A0 =A0puts "write something"
    > end


    You could replace the sleep(200) with a loop doing something like:
    sleeping a small amount of time (e.g.: 100ms), checking if there's
    user input available, act accordingly and sleeping again.


    --=20
    Luis Parravicini
    http://ktulu.com.ar/blog/
     
    Luis Parravicini, Oct 25, 2010
    #2
    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. Wet Basement
    Replies:
    1
    Views:
    2,534
    BobMonk
    Jul 15, 2003
  2. dpackwood
    Replies:
    3
    Views:
    1,816
  3. P McGinness
    Replies:
    0
    Views:
    298
    P McGinness
    Jan 14, 2004
  4. Rajat
    Replies:
    3
    Views:
    706
    Jorgen Grahn
    Jan 8, 2010
  5. VYAS ASHISH M-NTB837
    Replies:
    2
    Views:
    566
    Jan Kaliszewski
    Jan 7, 2010
Loading...

Share This Page