package Tak::Remote;

use Moo;

has router => (is => 'ro', required => 1);

has name => (is => 'ro', required => 1);

sub blocking_request {
  my ($self, @payload) = @_;
  local our $Request = $self->router->send_request($self, $self->name, @payload);
  local our $Done;
  local our @Result;
  $self->router->run_until($Done);
  return @Result;
}

sub send_response {
  my ($self, $tag, @result) = @_;
  {
    our $Request;
    die "Out of order response ${\$Request->tag}, expecting ${tag}"
      if $Request->tag ne $tag;
  }
  our @Result = @result;
  our $Done = 1;
}

1;
