From: Matt S Trout Date: Tue, 15 Nov 2011 08:39:27 +0000 (+0000) Subject: loop_upgrade X-Git-Tag: v0.001002~20 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=addc801e40b2b3ce69c002b38f57bda93bca6707;p=scpubgit%2FTak.git loop_upgrade --- diff --git a/Changes b/Changes index 26974f5..5ad88df 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,4 @@ + - add Tak->loop_upgrade - Provide a $client in repl objects - Support for -l/--local in Tak::Script diff --git a/lib/Tak.pm b/lib/Tak.pm index 92cc7dd..ce3ca2e 100644 --- a/lib/Tak.pm +++ b/lib/Tak.pm @@ -9,11 +9,17 @@ our $loop; sub loop { $loop ||= Tak::Loop->new } +sub loop_upgrade { + require IO::Async::Loop; + my $new_loop = IO::Async::Loop->new; + $loop->pass_watches_to($new_loop) if $loop; + $loop = $new_loop; +} + sub loop_until { my ($class, $done) = @_; return if $done; - my $loop = $class->loop; - $loop->loop_once until $_[1]; + $class->loop->loop_once until $_[1]; } sub await_all { diff --git a/lib/Tak/Loop.pm b/lib/Tak/Loop.pm index a1a4db3..09af744 100644 --- a/lib/Tak/Loop.pm +++ b/lib/Tak/Loop.pm @@ -8,6 +8,16 @@ has is_running => (is => 'rw', clearer => 'loop_stop'); has _read_watches => (is => 'ro', default => sub { {} }); has _read_select => (is => 'ro', default => sub { IO::Select->new }); +sub pass_watches_to { + my ($self, $new_loop) = @_; + foreach my $fh ($self->_read_select->handles) { + $new_loop->watch_io( + handle => $fh, + on_read_ready => $self->_read_watches->{$fh} + ); + } +} + sub watch_io { my ($self, %watch) = @_; my $fh = $watch{handle};