Skip to content

Instantly share code, notes, and snippets.

@deppp
Created October 10, 2009 01:34
Show Gist options
  • Save deppp/206495 to your computer and use it in GitHub Desktop.
Save deppp/206495 to your computer and use it in GitHub Desktop.
use common::sense;
use EV;
use AnyEvent;
use AnyEvent::Util;
use AnyEvent::CouchDB;
my @_queue = ();
my $_IS_RUNNING = 0;
sub _schedule;
sub _schedule {
while () {
if (! $_IS_RUNNING and my $cb = shift @_queue) {
$_IS_RUNNING = 1;
$cb->(AnyEvent::Util::guard { $_IS_RUNNING = 0; _schedule; });
} else {
last;
}
}
}
sub _wait {
push @_queue, $_[0];
_schedule if ! $_IS_RUNNING;
}
my $get_all_dbs = sub {
_wait sub {
my $couch = couch('http://localhost:5984/');
my $data = $couch->all_dbs->recv;
};
};
my @handles = map { AE::timer 0, 100.25, $get_all_dbs } (0 .. 100);
EV::loop;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment