File: TestIOAsync.pm

package info (click to toggle)
libobject-remote-perl 0.004000-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 488 kB
  • ctags: 248
  • sloc: perl: 2,408; makefile: 7
file content (32 lines) | stat: -rw-r--r-- 706 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
package TestIOAsync;

use Moo;
use Object::Remote;
use Object::Remote::Future;
use IO::Async::Loop;
use IO::Async::Process;
use IO::Async::LineStream;

Object::Remote->current_loop(our $Loop = IO::Async::Loop->new);

sub run {
  my ($self, $coderef) = @_;
  return future {
    my $f = shift;
    my $process = IO::Async::Process->new(
      command => [ 'ls' ],
      on_finish => sub {
        $Loop->remove($_[0]); $f->done; undef($f);
      },
    );
    my $line_stream = IO::Async::LineStream->new(
      on_read_line => sub { $coderef->($_[1]) },
      transport => $process->stdout,
    );
    $process->add_child($line_stream); # request cleanup
    $Loop->add($process);
    return $f;
  }
}

1;