make it actually exit when dead
[scpubgit/Object-Remote.git] / lib / Object / Remote.pm
index 35f5c03..7bb33c6 100644 (file)
@@ -9,10 +9,12 @@ has connection => (is => 'ro', required => 1);
 
 has id => (is => 'rwp');
 
-has proxy => (is => 'lazy', weak_ref => 1);
+has disarmed_free => (is => 'rwp');
 
-sub _build_proxy {
-  bless({ remote => $_[0] }, 'Object::Remote::Proxy');
+sub disarm_free { $_[0]->_set_disarmed_free(1); $_[0] }
+
+sub proxy {
+  bless({ remote => $_[0], method => 'call' }, 'Object::Remote::Proxy');
 }
 
 sub BUILD {
@@ -25,7 +27,7 @@ sub BUILD {
           class_call => $args->{class},
           $args->{constructor}||'new', @{$args->{args}||[]}
         )
-      )
+      )->{remote}->disarm_free->id
     );
   }
   $self->connection->register_remote($self);
@@ -40,17 +42,22 @@ sub call {
   $self->_await($self->connection->send(call => $self->id, $method, @args));
 }
 
+sub call_discard {
+  my ($self, $method, @args) = @_;
+  $self->connection->send_discard(call => $self->id, $method, @args);
+}
+
 sub _await {
   my ($self, $future) = @_;
   my $loop = $self->current_loop;
   $future->on_ready(sub { $loop->stop });
   $loop->run;
-  $future->get;
+  ($future->get)[0];
 }
 
 sub DEMOLISH {
   my ($self, $gd) = @_;
-  return if $gd;
+  return if $gd or $self->disarmed_free;
   $self->connection->send_free($self->id);
 }