NAME
Hypersonic::Future::Pool - Thread pool for async operations (OO interface)
SYNOPSIS
use Hypersonic::Future::Pool;
use Hypersonic::Future;
# Create multiple pools with different configurations
my $fast_pool = Hypersonic::Future::Pool->new(workers => 8);
my $slow_pool = Hypersonic::Future::Pool->new(workers => 2);
# Initialize pools
$fast_pool->init;
$slow_pool->init;
# Submit work to specific pools
my $f1 = Hypersonic::Future->new;
my $f2 = Hypersonic::Future->new;
$fast_pool->submit($f1, sub { quick_operation() });
$slow_pool->submit($f2, sub { slow_operation() });
# Check pool status (custom OPs - zero dispatch overhead)
say "Fast pool pending: " . $fast_pool->pending_count;
say "Slow pool initialized: " . $slow_pool->is_initialized;
# Process completed work (in event loop)
my $fd = $fast_pool->get_notify_fd;
# When fd is readable:
$fast_pool->process_ready;
# Cleanup
$fast_pool->shutdown;
$slow_pool->shutdown;
# Or use backward-compatible class methods
Hypersonic::Future::Pool->init_global(workers => 4);
my $pool = Hypersonic::Future::Pool->default_pool;
DESCRIPTION
Hypersonic::Future::Pool provides thread pools for offloading blocking operations. Each pool has its own worker threads, notify fd, and queues.
Objects are blessed references to integer slots in a C registry, following the same pattern as Hypersonic::Future. Hot-path methods like is_initialized and pending_count use custom OPs for zero dispatch overhead.
METHODS
new(%opts)
Create a new pool. Options:
- workers => N
-
Number of worker threads (default: 8)
- queue_size => N
-
Maximum queue depth (default: 4096)
init
Initialize the pool (start worker threads).
shutdown
Shutdown the pool (stop worker threads).
submit($future, $code, $args)
Submit work to be executed. The code runs in the main thread when a worker signals completion.
process_ready
Process completed operations, invoking Future callbacks.
is_initialized
Check if pool is running. Uses custom OP.
pending_count
Get count of pending operations. Uses custom OP.
get_notify_fd
Get the file descriptor for event loop integration.
workers
Get the number of worker threads.
slot
Get the internal slot number (for event loop integration).