use Tak::Client;
use Tak::Router;
-use Tak::MetaService;
use Tak::REPL;
use strictures 1;
-my $router = Tak::Router->new;
-
-$router->register(meta => Tak::MetaService->new(router => $router));
-
-my $client = Tak::Client->new(service => $router);
+my $client = Tak::Client->new(service => Tak::Router->new);
$client->curry('meta')->do(register => eval => 'Tak::EvalService');
has service => (is => 'ro', required => 1);
+has on_close => (is => 'ro', required => 1);
+
sub BUILD {
weaken(my $self = shift);
my $channel = $self->channel;
sub receive_result {
my ($self, $tag, @payload) = @_;
- $self->requests->{$tag}->result(@payload);
+ (delete $self->requests->{$tag})->result(@payload);
}
sub receive_message {
$self->service->receive(@payload);
}
+sub receive_close {
+ my ($self, @payload) = @_;
+ $self->on_close->(@payload);
+}
+
1;
);
my $receiver = $self->_set_receiver(
Tak::ConnectionReceiver->new(
- channel => $channel, service => $args->{listening_service}
+ channel => $channel, service => $args->{listening_service},
+ on_close => $args->{on_close},
)
);
}
my ($self) = @_;
my $kid_pid = IPC::Open2::open2(my $kid_out, my $kid_in, $^X, '-')
or die "Couldn't open2 child: $!";
- io($kid_in)->print(io('maint/mk-fat |')->all, "__END__\n");
+ $kid_in->print(io('maint/mk-fat |')->all, "__END__\n");
my $connection = Tak::ConnectionService->new(
read_fh => $kid_out, write_fh => $kid_in,
listening_service => Tak::Router->new
if (my $unpacked = $self->_unpack_line($line)) {
return $unpacked;
}
+ } else {
+ return [ 'close', 'channel' ];
}
}
sub loop_once {
my ($self) = @_;
my $read = $self->_read_watches;
- my ($readable) = IO::Select->select($self->_read_select);
+ my ($readable) = IO::Select->select($self->_read_select, undef, undef, 0.5);
+ die "FFFFFUUUUU: $!" unless $readable;
foreach my $fh (@$readable) {
$read->{$fh}();
}
open my $stdin, '<&', \*STDIN;
open my $stdout, '>&', \*STDOUT;
close STDIN; close STDOUT;
+ my $done;
my $connection = Tak::ConnectionService->new(
read_fh => $stdin, write_fh => $stdout,
- listening_service => Tak::Router->new
+ listening_service => Tak::Router->new,
+ on_close => sub { $done = 1 }
);
- Tak->loop->loop_forever;
+ Tak->loop_until($done);
}
1;