Permalink
Browse files

Add simple condvar feature as AnyEvent is

  • Loading branch information...
1 parent d52c76c commit 8136ac5ba4e02608141df8ba41af8dd8b61e43c2 @am0c am0c committed Oct 30, 2012
Showing with 26 additions and 0 deletions.
  1. +26 −0 lib/MuEvent.pm
View
@@ -6,6 +6,23 @@ my @sockets;
my @idlers;
my $since;
+class MuEvent::Condvar {
+ has &.cb;
+ has @.sent is rw;
+ has $.flag is rw = False;
+
+ method send(*@data) {
+ &.cb() if &.cb;
+ @.sent = @data if @data;
+ $.flag = True;
+ }
+ method recv() {
+ $since = clock() unless $since.defined;
+ MuEvent::_poll until $.flag;
+ return @.sent but True;
+ }
+}
+
#= Add an event run after a certain amount of time
our sub timer(:&cb!, :$after!, :$interval, :%params) {
@timers.push: {
@@ -38,6 +55,15 @@ our sub run {
}
}
+our sub _poll {
+ run-once()
+}
+
+#= Condvar
+our sub condvar(:&cb?) {
+ MuEvent::Condvar.new( cb => &cb );
+}
+
sub run-timers {
my $seen-action = False;
for @timers -> $e is rw {

0 comments on commit 8136ac5

Please sign in to comment.