fixup start, add then::
[scpubgit/Object-Remote.git] / t / start_core.t
1 use strictures 1;
2 use 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
56 my $res;
57
58 S1S->start::get_s2->then::get_s3->on_ready(sub { ($res) = $_[0]->get });
59
60 is($res, 'S3', 'Synchronous code ok');
61
62 undef($res);
63
64 S1F->start::get_s2->then::get_s3->on_ready(sub { ($res) = $_[0]->get });
65
66 ok(!$S2F::C, 'Second future not yet constructed');
67
68 $S1F::C->();
69
70 ok($S2F::C, 'Second future constructed after first future completed');
71
72 ok(!$res, 'Nothing happened yet');
73
74 $S2F::C->();
75
76 is($res, 'S3', 'Asynchronous code ok');
77
78 done_testing;