develooper Front page | perl.perl6.language | Postings from April 2005

alarm() and later()

Thread Next
From:
Gaal Yahas
Date:
April 18, 2005 13:05
Subject:
alarm() and later()
Message ID:
20050418200423.GD20186@sike.forum2.org
Two things popped up while implementing a demo version of alarm() today.

1. In perl5 and in most underlying libraries, alarm() has 1 second
granularity (and a possible 1 second error on top of that). Can we have
the alarm builtin not assume the worst, and take a Num instead of an
Int, so that on some systems at least we get higher resolution sleeps?

2. Since signals are so global and sometimes we want something else,
how about a variation on the traditional u?alarm theme, in which you can
pass an optional closure to alarm() that will get called back instead of
having a SIGALRM raised?

     multi sub alarm(: Num ?$timeout = $CALLER::_,
                       Num ?$interval,
                       Code ?$callback) returns Int

This should be reentrant and allow multiple uses. The Int return is an
id on the future event so you can cancel it. (Which needs speccing.
Possibly this could return a reference to some object instead of an
id?) If the alarm builtin is getting too overloaded, I propose the
closure version be named "later".


-- 
Gaal Yahas <gaal@forum2.org>
http://gaal.livejournal.com/

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About