Re: non-blocking loop delay



On Sun, 2005-06-12 at 18:13 -0400, zentara wrote:
Hi,
I'm either missing something, or I'm searching for something which dosn't
exist.  Is there a way to slow down a loop, without blocking the gui?
I know the code below, could (and probably should) be rewritten using
Glib::Timeout->add ()  instead of a for loop, but what if I wanted or needed
the for loop.

You can use both, by taking advantage of Perl closures for the 'loop'
index and the fact that if the routine you schedule with Timeout->add
returns TRUE, it will be rescheduled:

  my $i = 1;
  Glib::Timeout->add(100,
    sub {
      return FALSE if $i > 100;
      # do stuff here
      $i++;
      return TRUE
    }
  );

Cheers
Grant




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]