NAME
Coro::Countdown - a counter that signals when it reaches 0
VERSION
version 0.01
SYNOPSIS
use Coro;
use Coro::Countdown;
my $counter = Coro::Countdown->new;
$counter->inc;
async { $counter->dec };
# Block until $counter->dec is called
$counter->join;
DESCRIPTION
Oftentimes it is necessary to wait until all users of a resource have completed before a program may continue. Examples of this include a pool of pending network requests, etc. A countdown signal will broadcast to any waiters once all "checked out" resources have been "returned".
METHODS
new
Optionally takes an initial value, defaulting to 0.
join
Cedes until the count decrements to 0. If the counter is already at 0, returns immediately.
count
Returns the current counter value.
up
Increments the counter value ("checks out" a resource).
down
Decrements the counter value ("returns" the resource). If the counter reaches 0, all watchers are signaled and the counter resets. It is then ready to be reused.
AUTHOR
Jeff Ober <sysread@fastmail.fm>
COPYRIGHT AND LICENSE
This software is copyright (c) 2017 by Jeff Ober.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.