Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Move subs around and document the outside-visible ones

  • Loading branch information...
commit 1dc385865feff70a68ac3a5dc538851631327d4d 1 parent f4b61ff
Tadeusz Sośnierz authored
Showing with 18 additions and 13 deletions.
  1. +18 −13 lib/MuEvent.pm
31 lib/MuEvent.pm
View
@@ -1,3 +1,4 @@
+#= Event-driven programming in Perl 6
module MuEvent;
my @timers;
@@ -5,10 +6,7 @@ my @sockets;
my @idlers;
my $since;
-sub clock {
- nqp::p6box_n(pir::time__n())
-}
-
+#= Add an event run after a certain amount of time
our sub timer(:&cb!, :$after!, :$interval, :%params) {
@timers.push: {
:$after, :$interval, :&cb,
@@ -17,6 +15,7 @@ our sub timer(:&cb!, :$after!, :$interval, :%params) {
};
}
+#= Add an IO::Socket to observe
our sub socket(:&cb!, :$socket!, :$poll where 'r'|'w', :%params) {
my $p = $poll eq 'r' ?? 1 !! 2;
@sockets.push: {
@@ -26,6 +25,19 @@ our sub socket(:&cb!, :$socket!, :$poll where 'r'|'w', :%params) {
};
}
+#= Add an event to be run when event loop is idle
+our sub idle(:&cb!, :%params) {
+ @idlers.push: { :&cb, :%params }
+}
+
+#= Run the event loop
+our sub run {
+ $since = clock();
+ loop {
+ run-once()
+ }
+}
+
sub run-timers {
my $seen-action = False;
for @timers -> $e is rw {
@@ -61,15 +73,8 @@ sub run-sockets {
return $seen-action;
}
-our sub idle(:&cb!, :%params) {
- @idlers.push: { :&cb, :%params }
-}
-
-our sub run {
- $since = clock();
- loop {
- run-once()
- }
+sub clock {
+ nqp::p6box_n(pir::time__n())
}
sub run-once {
Please sign in to comment.
Something went wrong with that request. Please try again.