Re: non-blocking loop delay



* Grant McLean <grant mclean net nz> [2005-06-13 00:30]:
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
    }
  );

Or maybe a little cleaner,

    sub {
        # do stuff here
        $i++;
        return $i > 100;
    }

Regards,
-- 
#Aristotle
*AUTOLOAD=*_=sub{s/(.*)::(.*)/print$2,(",$\/"," ")[defined wantarray]/e;$1};
&Just->another->Perl->hacker;



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