Sophie

Sophie

distrib > Mageia > 1 > x86_64 > by-pkgid > 3edfe3d0de8f94c5c6619c7963f84a7a > files > 55

perl-Coro-5.372.0-1.mga1.x86_64.rpm

#!/usr/bin/perl

# the classical producer/consumer example.
# one process produces items, send s a signal.
# another process waits for that signal and
# consumed the item.

use Coro;
use Coro::Signal;

my $produced = new Coro::Signal;
my $consumed = new Coro::Signal;
my $finished = new Coro::Signal;

async {
   for (0..9) {
      print "produced something\n";
      $produced->send;
      $consumed->wait;
   }
   print "work done\n";
   $finished->send;
};

async {
   while () {
      $produced->wait;
      print "consuming something\n";
      $consumed->send;
   }
};

$finished->wait;

print "job finished\n";