Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add simple condvar feature as AnyEvent is

  • Loading branch information...
commit 8136ac5ba4e02608141df8ba41af8dd8b61e43c2 1 parent d52c76c
Hojung Youn am0c authored
Showing with 26 additions and 0 deletions.
  1. +26 −0 lib/MuEvent.pm
26 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 {
Please sign in to comment.
Something went wrong with that request. Please try again.