Created
October 10, 2009 01:34
-
-
Save deppp/206495 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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