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 <[EMAIL PROTECTED]>
http://gaal.livejournal.com/

Reply via email to