AnyEvent::Semaphore - Semaphore implementation for AnyEvent
use AnyEvent::Semaphore; my $sem = AnyEvent::Semaphore->new(5); ... my $watcher = $sem->down( sub { ... } ); ... undef $watcher; # semaphore up
This module provides a semaphore implementation intended to be used with the AnyEvent framework.
It tries to be as simple as possible and to follow AnyEvent style.
The module provides the following methods:
Creates a new semaphore object of the given size.
Queues a down (or wait) operation on the semaphore. The given callback will be eventually invoked when the resouce guarded by the semaphore becomes free.
The call returns a watcher object.
After the resource is assigned and the callback invoked, destroying the watcher frees the resource (it is the equivalent of the up or signal operation).
Destroying the watcher before the resource is asigned just cancels the down operation.
Gets or sets the semaphore size.
When the size is increased, queued operations will be processed.
Returns the number of slots currently used.
The Wikipedia page on semaphores.
AnyEvent.
Salvador Fandiño, <sfandino@yahoo.com>
Copyright (C) 2013 by Qindel Formación y Servicios S.L.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.14.2 or, at your option, any later version of Perl 5 you may have available.
To install AnyEvent::Semaphore, copy and paste the appropriate command in to your terminal.
cpanm
cpanm AnyEvent::Semaphore
CPAN shell
perl -MCPAN -e shell install AnyEvent::Semaphore
For more information on module installation, please visit the detailed CPAN module installation guide.