Skip Menu |

This queue is for tickets about the POSIX-RT-Timer CPAN distribution.

Report information
The Basics
Id: 58427
Status: resolved
Priority: 0/
Queue: POSIX-RT-Timer

People
Owner: Nobody in particular
Requestors: jdrago_999 [...] yahoo.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



I would like to "stop" a timer when I want to - from within the callback. Something like this: my $timer; $timer = POSIX::RT::Timer->new( value => 0.1, interval => 1 / 90, # 90hz callback => sub { # Do stuff, but only until we are tired of it... $timer->stop() if $counter++ >= 90; } ); Any chance for the addition of a "stop" method?
Subject: timer.pl
use threads; use POSIX::RT::Timer; use POSIX 'pause'; my $counter = 1; async { my $timer; $timer = POSIX::RT::Timer->new( value => 0.1, interval => 1 / 90, # 90 times per second, callback => sub { warn "Hello, World!: $counter\n"; $timer->stop() if $counter++ >= 90; } ); }; pause() while $counter < 90; $_->join foreach threads->list;
Actually, that's already possible by calling $timer->set_timeout(0); though that should probably be documented more clearly. Leon