X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=scpubgit%2FObject-Remote.git;a=blobdiff_plain;f=lib%2FObject%2FRemote%2FRole%2FConnector.pm;h=cc8684b6b0bf703090da1cfec935348a9d42aa0a;hp=16f0d5236eb0643c855931130cb4342d3ee82865;hb=12fb4a80d68ad14c18a35f60cc6d8a671f728ac9;hpb=befabdee3a3a75da8dd2fd21a2a6c80d8ed0bcff diff --git a/lib/Object/Remote/Role/Connector.pm b/lib/Object/Remote/Role/Connector.pm index 16f0d52..cc8684b 100644 --- a/lib/Object/Remote/Role/Connector.pm +++ b/lib/Object/Remote/Role/Connector.pm @@ -1,15 +1,47 @@ package Object::Remote::Role::Connector; use Module::Runtime qw(use_module); +use Object::Remote::Future; use Moo::Role; requires '_open2_for'; sub connect { my $self = shift; - my %args; - @args{qw(send_to_fh receive_from_fh child_pid)} = $self->_open2_for(@_); - return use_module('Object::Remote::Connection')->new(\%args); + my ($send_to_fh, $receive_from_fh, $child_pid) = $self->_open2_for(@_); + my $channel = use_module('Object::Remote::ReadChannel')->new( + fh => $receive_from_fh + ); + return future { + my $f = shift; + $channel->on_line_call(sub { + if ($_[0] eq "Shere") { + $f->done( + use_module('Object::Remote::Connection')->new( + send_to_fh => $send_to_fh, + read_channel => $channel, + child_pid => $child_pid, + ) + ); + } else { + $f->fail("Expected Shere from remote but received: $_[0]"); + } + undef($channel); + }); + $channel->on_close_call(sub { + $f->fail("Channel closed without seeing Shere: $_[0]"); + undef($channel); + }); + Object::Remote->current_loop + ->watch_time( + after => 5, + code => sub { + $f->fail("Connection timed out") unless $f->is_ready; + undef($channel); + } + ); + $f; + } } 1;