Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sysread/coro-countdown

A counter that signals when it reaches 0 for coro and perl
https://github.com/sysread/coro-countdown

Last synced: about 1 month ago
JSON representation

A counter that signals when it reaches 0 for coro and perl

Awesome Lists containing this project

README

        

=pod

=encoding UTF-8

=head1 NAME

Coro::Countdown - a counter that signals when it reaches 0

=head1 VERSION

version 0.02

=head1 SYNOPSIS

use Coro;
use Coro::Countdown;

my $counter = Coro::Countdown->new;
$counter->up;

async { $counter->down };

# Block until $counter->down is called
$counter->join;

=head1 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".

=head1 METHODS

=head2 new

Optionally takes an initial value, defaulting to 0.

=head2 join

Cedes until the count decrements to 0. If the counter is already at 0, returns
immediately.

=head2 count

Returns the current counter value.

=head2 up

Increments the counter value ("checks out" a resource).

=head2 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.

=head1 AUTHOR

Jeff Ober

=head1 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.

=cut