The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

RPC::Switch::Client::Tiny::Async - Child handling for async workers

SYNOPSIS

  use RPC::Switch::Client::Tiny::Async;

  sub trace_cb {
        my ($type, $msg) = @_;
        printf "%s: %s\n", $type, to_json($msg, {pretty => 0, canonical => 1});
  }

  my $async = RPC::Switch::Client::Tiny::Async->new(trace_cb => \&trace_cb);

  sub child_handler {
        my ($self, $fh) = @_;
        my $req = <$fh>;
        chomp $req;

        print "child $$ got: $req\n";
        print $fh "pong\n";
        $fh->flush();
        exit 0;
  }
  my $worker = bless {};
  my $child = $async->child_start($worker);

  print {$child->{reader}} "ping\n";
  $child->{reader}->flush();
  my $res = readline($child->{reader});
  chomp $res;

  $async->child_finish($child, 'done');
  $async->childs_reap();

DESCRIPTION

The worker_child methods are private and handle the childs used for the async client->work mode.

AUTHORS

Barnim Dzwillo @ Strato AG