remove last vestiges of previous layout
[scpubgit/Tak.git] / lib / Tak / Client.pm
CommitLineData
31a246e4 1package Tak::Client;
2
3use Tak;
4use Tak::Request;
5use Moo;
6
7has service => (is => 'ro', required => 1);
8
9has curried => (is => 'ro', default => sub { [] });
10
11sub curry {
12 my ($self, @curry) = @_;
13 (ref $self)->new(%$self, curried => [ @{$self->curried}, @curry ]);
14}
15
16sub send {
17 my ($self, @message) = @_;
18 $self->service->receive(@{$self->curried}, @message);
19}
20
21sub start {
22 my ($self, $register, @payload) = @_;
23 my $req = $self->_new_request($register);
24 $self->service->start_request($req, @{$self->curried}, @payload);
25 return $req;
26}
27
28sub request_class { 'Tak::Request' }
29
30sub _new_request {
31 my ($self, $args) = @_;
32 $self->request_class->new($args);
33}
34
35sub do {
77bf1d9b 36 shift->result_of(@_)->get;
37}
38
39sub result_of {
31a246e4 40 my ($self, @payload) = @_;
41 my $done;
42 my $result;
43 my $req = $self->start({
44 on_result => sub { $result = shift },
45 }, @payload);
46 Tak->loop_until($result);
77bf1d9b 47 return $result;
31a246e4 48}
49
501;