Coro::Countdown - a counter that signals when it reaches 0
version 0.01
use Coro; use Coro::Countdown; my $counter = Coro::Countdown->new; $counter->inc; async { $counter->dec }; # Block until $counter->dec is called $counter->join;
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".
Optionally takes an initial value, defaulting to 0.
Cedes until the count decrements to 0. If the counter is already at 0, returns immediately.
Returns the current counter value.
Increments the counter value ("checks out" a resource).
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.
Jeff Ober <sysread@fastmail.fm>
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.
To install Coro::Countdown, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Coro::Countdown
CPAN shell
perl -MCPAN -e shell install Coro::Countdown
For more information on module installation, please visit the detailed CPAN module installation guide.