has child_pid => (is => 'ro');
+has is_ready => (is => 'rwp', trigger => sub {
+ my ($self, $value) = @_;
+ $self->ready_future->done if $value;
+});
+
+has ready_future => (is => 'lazy');
+
+sub _build_ready_future { CPS::Future->new }
+
has _receive_data_buffer => (is => 'ro', default => sub { my $x = ''; \$x });
has local_objects_by_id => (is => 'ro', default => sub { {} });
return $remote;
}
+sub await_ready {
+ my ($self) = @_;
+ return if $self->is_ready;
+ await_future($self->ready_future);
+}
+
sub send_free {
my ($self, $id) = @_;
delete $self->remote_objects_by_id->{$id};
sub _send {
my ($self, $to_send) = @_;
+ $self->await_ready unless $self->is_ready;
+
print { $self->send_to_fh } $self->_serialize($to_send)."\n";
}
sub _receive_data_from {
my ($self, $fh) = @_;
my $rb = $self->_receive_data_buffer;
+ my $ready = $self->is_ready;
if (sysread($fh, $$rb, 1024, length($$rb)) > 0) {
while ($$rb =~ s/^(.*)\n//) {
- $self->_receive($1);
+ if ($ready) {
+ $self->_receive($1);
+ } else {
+ my $line = $1;
+ die "New remote container did not send Shere - got ${line}"
+ unless $line eq "Shere";
+ $self->_set_is_ready($ready = 1);
+ }
}
} else {
$self->on_close->done();
use Object::Remote::FatNode;
use Object::Remote::ModuleSender;
+use Object::Remote::Handle;
use IPC::Open2;
use Moo;
around connect => sub {
my ($orig, $self) = (shift, shift);
my $conn = $self->$orig(@_);
- Object::Remote->new(
+ Object::Remote::Handle->new(
connection => $conn,
class => 'Object::Remote::ModuleLoader',
args => { module_sender => Object::Remote::ModuleSender->new }
sub AUTOLOAD {
my $invocant = shift;
- my ($method) = our $AUTOLOAD =~ /([^:]+)$/;
+ my ($method) = our $AUTOLOAD =~ /^start::(.+)$/;
if (ref($invocant) eq 'ARRAY') {
return [ map $_->${\"start::${method}"}, @$invocant ];
}
my $self = shift;
my %args;
@args{qw(send_to_fh receive_from_fh child_pid)} = $self->_open2_for(@_);
- my $line = readline($args{receive_from_fh});
- unless ($line eq "Shere\n") {
- die "New remote container did not send Shere - got ${line}";
- }
return use_module('Object::Remote::Connection')->new(\%args);
}