File: start_core.t

package info (click to toggle)
libobject-remote-perl 0.004000-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 488 kB
  • ctags: 248
  • sloc: perl: 2,408; makefile: 7
file content (105 lines) | stat: -rw-r--r-- 1,509 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
use strictures 1;
use Test::More;
use Object::Remote;
use File::Spec;

$ENV{OBJECT_REMOTE_TEST_LOGGER} = 1;

{
  package S1S;

  use Moo;

  sub get_s2 {
    S2S->new
  }
}

{
  package S1F;

  use Object::Remote::Future;
  use Moo;

  our $C;

  sub get_s2 {
    shift->maybe::start::_real_get_s2;
  }

  sub _real_get_s2 {
    future {
      my $f = shift;
      $C = sub { $f->done(S2F->new); undef($f); undef($C); };
      $f;
    }
  }
}

{
  package S2S;

  use Moo;

  sub get_s3 { 'S3' }
}

{
  package S2F;

  use Object::Remote::Future;
  use Moo;

  our $C;

  sub get_s3 {
    future {
      my $f = shift;
      $C = sub { $f->done('S3'); undef($f); undef($C); };
      $f;
    }
  }
}

my $res;

my @keep;

push @keep,
  S1S->start::get_s2->then::get_s3->on_ready(sub { ($res) = $_[0]->get });

is($res, 'S3', 'Synchronous code ok');

undef($res);

push @keep,
  S1F->start::get_s2->then::get_s3->on_ready(sub { ($res) = $_[0]->get });

ok(!$S2F::C, 'Second future not yet constructed');

$S1F::C->();

ok($S2F::C, 'Second future constructed after first future completed');

ok(!$res, 'Nothing happened yet');

$S2F::C->();

is($res, 'S3', 'Asynchronous code ok');

is(S1S->get_s2->get_s3, 'S3', 'Sync without start');

Object::Remote->current_loop->watch_time(
  after => 0.1,
  code => sub {
    $S1F::C->();
    Object::Remote->current_loop->watch_time(
      after => 0.1,
      code => sub { $S2F::C->() }
    );
  }
);

is(S1F->get_s2->get_s3, 'S3', 'Async without start');

done_testing;