Skip to content

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

Notifications You must be signed in to change notification settings

sysread/Coro-Countdown

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NAME

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

VERSION

version 0.02

SYNOPSIS

use Coro;
use Coro::Countdown;

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

async { $counter->down };

# Block until $counter->down 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.

About

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

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages