The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#!/usr/bin/perl
use strict;
use warnings;
use Coro;
use Coro::AnyEvent;
use AnyEvent::CouchDB;
use Data::Dump 'pp';
my $couch = couch();
my $bad   = couch('http://bad/');
my $done  = AnyEvent->condvar;

sub p(&) {
  $done->begin;
  my $code = shift;
  my $data;
  eval { $data = $code->(); };
  if ($@) {
    print $@, "\n";
  } else {
    print pp($data), "\n";
  }
  $done->end;
}

async { print "hello, world\n" };
for (1 .. 4) {
  async { p { ($couch->info->recv)    } };
  async { p { ($couch->all_dbs->recv) } };
  async { p { ($bad->info->recv)      } };
  async { p { ($bad->all_dbs->recv)   } };
}
async { print "hello, again, world\n" };
async { print "*** please be patient, and let the bad requests timeout. ***\n" };
async { 
  $done->recv;
  print "----\n";
  print "Did you see how the bad requests didn't stop the good requests?\n";
  exit;
};

schedule;