fixup start, add then::
[scpubgit/Object-Remote.git] / t / start_core.t
CommitLineData
11e7c8a5 1use strictures 1;
2use Test::More;
3
4{
5 package S1S;
6
7 use Moo;
8
9 sub get_s2 {
10 S2S->new
11 }
12}
13
14{
15 package S1F;
16
17 use Object::Remote::Future;
18 use Moo;
19
20 our $C;
21
22 sub get_s2 {
23 future {
24 my $f = shift;
25 $C = sub { $f->done(S2F->new); undef($f); };
26 $f;
27 }
28 }
29}
30
31{
32 package S2S;
33
34 use Moo;
35
36 sub get_s3 { 'S3' }
37}
38
39{
40 package S2F;
41
42 use Object::Remote::Future;
43 use Moo;
44
45 our $C;
46
47 sub get_s3 {
48 future {
49 my $f = shift;
50 $C = sub { $f->done('S3'); undef($f); };
51 $f;
52 }
53 }
54}
55
56my $res;
57
58S1S->start::get_s2->then::get_s3->on_ready(sub { ($res) = $_[0]->get });
59
60is($res, 'S3', 'Synchronous code ok');
61
62undef($res);
63
64S1F->start::get_s2->then::get_s3->on_ready(sub { ($res) = $_[0]->get });
65
66ok(!$S2F::C, 'Second future not yet constructed');
67
68$S1F::C->();
69
70ok($S2F::C, 'Second future constructed after first future completed');
71
72ok(!$res, 'Nothing happened yet');
73
74$S2F::C->();
75
76is($res, 'S3', 'Asynchronous code ok');
77
78done_testing;