AnyEvent-Tools
view release on metacpan or search on metacpan
lib/AnyEvent/Tools.pm view on Meta::CPAN
use the function.
=head2 rw_mutex
returns unlocked read-write mutex.
This object provides the following methods:
=head3 rlock(CODEREF)
You declare that You want to lock mutex for reading. When it is
possible the mutex will be locked and Your callback will be called.
There may be a lot of read processes running simultaneously
that catch the lock.
=head3 wlock(CODEREF).
You declare that You want to lock mutex for writing. When it is
possible the mutex will be locked and Your callback will be called.
There may be only one write process that catches the lock.
Both callbacks receive a guard to hold the mutex locked.
=head3 rlock_limit(NUMBER)
Get/Set count limit for rlock. If an rlock request is come and this limit
is reached the request will be queued.
=head3 is_locked
Returns B<TRUE> if the mutex has 'read' or 'write' lock status.
=head3 is_rlocked
Returns B<TRUE> if the mutex has 'read' lock status.
B<Important>: this method returns B<FALSE> if the mutex is
wlocked (L<is_wlocked>), so if You want to know if any lock
is set, use the function L<is_locked>.
=head3 is_wlocked
Returns B<TRUE> if the mutex has 'write' lock status.
Usually You shoudn't use is_[rw]?locked functions.
=head2 async_repeat(COUNT, CALLBACK [, DONE_CALLBACK ])
Repeats calling Your callback(s).
async_repeat 10, sub { $count++ };
async_repeat 20, sub { $count++ }, sub { $done = 1 };
The function async_repeat returns the guard if it is called in non-void
context. Destroy the guard if You want to cancel iterations.
Iteration callback receives the following arguments:
=over
=item 1. guard
The next iteration will not start until the guard is destroyed.
=item 2. iteration number
The number of current iteration.
=item 3. first_flag
TRUE on the first iteration.
=item 4. last_flag
TRUE on the last iteration.
=back
=head2 async_for(HASREF|ARRAYREF, CALLBACK [, DONE_CALLBACK ]);
Calls Your callbacks for each array or hash element.
The function returns the guard if it is called in non-void
context. Destroy the guard if You want to cancel iterations.
If You process an array using the function, iteration callback
will receive the following arguments:
=over
=item 1. guard
The next iteration will not start until the guard is destroyed.
=item 2. element
Next array element.
=item 3. index
Index of array element.
=item 4. first_flag
The iteration is the first.
=item 5. last_flag
The iteration is the last.
=back
If You process a hash using the function, iteration callback
will receive the following arguments:
=over
=item 1. guard
The next iteration will not start until the guard is destroyed.
=item 2. key
=item 3. value
=item 4. first_flag
The iteration is the first.
=item 5. last_flag
The iteration is the last.
=back
=head2 async_rfor(HASREF|ARRAYREF, CALLBACK [, DONE_CALLBACK ]);
The same as async_for but has reverse sequence.
=head2 pool
Returns the object that incapsulates object collection. You can cacth one
object of the collection using the method:
( run in 0.558 second using v1.01-cache-2.11-cpan-71847e10f99 )