The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Async::ResourcePool - Resource pooling for asynchronous programs.

DESCRIPTION

This module implements the simple functionality of creating a source pool for event-based/asynchronous programs. It provides consumers with the ability to have some code execute whenever a resource happens to be ready. Further, it allows resources to be categorized (by label) and limited as such.

CONSTRUCTOR

new [ ATTRIBUTES ]

ATTRIBUTES

factory -> CodeRef(POOL, CodeRef(RESOURCE, MESSAGE))

The factory for generating the resource. The factory is a subroutine reference which accepts an instance of this object and a callback as a reference. The callback, to be invoked when the resource has been allocated.

If no resource could be allocated due to error, then undef should be supplied with the second argument being a string describing the failure.

limit -> Int

The number of resources to create per label.

Optional.

has_waiters -> Bool

A flag indicating whether or not this pool currently has a wait queue.

Read-only.

has_available_queue -> Bool

A flag indicating whether or not this pool has any idle resources available.

Read-only.

size -> Int

The current size of the pool.

Read-only.

METHODS

lease CALLBACK(RESOURCE, MESSAGE)

Request a lease, with a callback invoked when the resource becomes available. The first argument of the callback will be the resource, if it was able to be granted, the second argument of the callback will be the error message, which will only be defined if first argument is not.

release RESOURCE

Return a resource to the pool. This will signal any waiters which haven't yet received a callback.

invalidate RESOURCE

Invalidate a resource, signaling that it is no longer valid and no longer can be distributed by this pool. This will allocate another resource if there are any waiters.