[PATCH] number of pending events

[email protected] (Graham Barr)
Newsgroups perl.loop
Message-ID <[email protected]>
The attached patch allows you to obtain the number of events
for a watcher that are still in the event queue. It also removes
unwanted ;'s from the typemap.

The situation where I have used this to force an event to
happen, unless I know one is already pending. eg

$idle = Event->idle( cb => sub { warn "idle" }, parked => 1);

then when I want this event to happen I can do

  $idle->now unless $idle->pending;

Graham.
patch (text/plain, 1 KB)
--- Event-0.63/lib/Event.pod.orig	Fri Feb  4 22:06:54 2000
+++ Event-0.63/lib/Event.pod	Fri Feb  4 22:08:47 2000
@@ -179,6 +179,11 @@
 
 Reports whether the C<$watcher> is suspended.
 
+=item $watcher->pending
+
+Returns how many events this watcher has with the callback still pending
+in the event queue.
+
 =back
 
 =head2 Watcher Types
--- Event-0.63/Event.xs.orig	Wed Feb  2 18:21:15 2000
+++ Event-0.63/Event.xs	Fri Feb  4 22:05:07 2000
@@ -531,6 +531,13 @@
 	}
 }
 
+int
+pe_watcher::pending()
+	CODE:
+	RETVAL = THIS->event_counter;
+	OUTPUT:
+	RETVAL
+
 void
 pe_watcher::again()
 	CODE:
--- Event-0.63/typemap.orig	Fri Feb  4 22:03:51 2000
+++ Event-0.63/typemap	Fri Feb  4 22:04:09 2000
@@ -6,15 +6,15 @@
 INPUT
 
 O_WATCHER
-	$var = ($type) sv_2watcher($arg);
+	$var = ($type) sv_2watcher($arg)
 
 O_EVENT
-	$var = ($type) sv_2event($arg);
+	$var = ($type) sv_2event($arg)
 
 OUTPUT
 
 O_WATCHER
-	croak("use watcher_2sv($var)");
+	croak("use watcher_2sv($var)")
 
 O_EVENT
-	croak("use event_2sv($var)");
+	croak("use event_2sv($var)")
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.