Commit | Line | Data |
11e7c8a5 |
1 | use strictures 1; |
2 | use Test::More; |
a7111726 |
3 | use Object::Remote; |
4 | use File::Spec; |
11e7c8a5 |
5 | |
abef6e5b |
6 | $ENV{OBJECT_REMOTE_TEST_LOGGER} = 1; |
f129bfaf |
7 | |
11e7c8a5 |
8 | { |
9 | package S1S; |
10 | |
11 | use Moo; |
12 | |
13 | sub get_s2 { |
14 | S2S->new |
15 | } |
16 | } |
17 | |
18 | { |
19 | package S1F; |
20 | |
21 | use Object::Remote::Future; |
22 | use Moo; |
23 | |
24 | our $C; |
25 | |
26 | sub get_s2 { |
9822fc76 |
27 | shift->maybe::start::_real_get_s2; |
28 | } |
29 | |
30 | sub _real_get_s2 { |
11e7c8a5 |
31 | future { |
32 | my $f = shift; |
a7111726 |
33 | $C = sub { $f->done(S2F->new); undef($f); undef($C); }; |
11e7c8a5 |
34 | $f; |
35 | } |
36 | } |
37 | } |
38 | |
39 | { |
40 | package S2S; |
41 | |
42 | use Moo; |
43 | |
44 | sub get_s3 { 'S3' } |
45 | } |
46 | |
47 | { |
48 | package S2F; |
49 | |
50 | use Object::Remote::Future; |
51 | use Moo; |
52 | |
53 | our $C; |
54 | |
55 | sub get_s3 { |
56 | future { |
57 | my $f = shift; |
a7111726 |
58 | $C = sub { $f->done('S3'); undef($f); undef($C); }; |
11e7c8a5 |
59 | $f; |
60 | } |
61 | } |
62 | } |
63 | |
64 | my $res; |
65 | |
bc06e921 |
66 | my @keep; |
67 | |
68 | push @keep, |
69 | S1S->start::get_s2->then::get_s3->on_ready(sub { ($res) = $_[0]->get }); |
11e7c8a5 |
70 | |
71 | is($res, 'S3', 'Synchronous code ok'); |
72 | |
73 | undef($res); |
74 | |
bc06e921 |
75 | push @keep, |
76 | S1F->start::get_s2->then::get_s3->on_ready(sub { ($res) = $_[0]->get }); |
11e7c8a5 |
77 | |
78 | ok(!$S2F::C, 'Second future not yet constructed'); |
79 | |
80 | $S1F::C->(); |
81 | |
82 | ok($S2F::C, 'Second future constructed after first future completed'); |
83 | |
84 | ok(!$res, 'Nothing happened yet'); |
85 | |
86 | $S2F::C->(); |
87 | |
88 | is($res, 'S3', 'Asynchronous code ok'); |
89 | |
a7111726 |
90 | is(S1S->get_s2->get_s3, 'S3', 'Sync without start'); |
91 | |
befabdee |
92 | Object::Remote->current_loop->watch_time( |
93 | after => 0.1, |
94 | code => sub { |
95 | $S1F::C->(); |
96 | Object::Remote->current_loop->watch_time( |
97 | after => 0.1, |
98 | code => sub { $S2F::C->() } |
99 | ); |
a7111726 |
100 | } |
101 | ); |
102 | |
103 | is(S1F->get_s2->get_s3, 'S3', 'Async without start'); |
104 | |
11e7c8a5 |
105 | done_testing; |