Channel::capacity

(PHP 8.6+, True Async 1.0)

public Channel::capacity(): int

Returns the channel capacity set at creation time via the constructor.

The value does not change during the channel’s lifetime.

Return values

The channel buffer capacity (int).

Examples

Example #1 Checking capacity

<?php

use Async\Channel;

$rendezvous = new Channel();
echo $rendezvous->capacity(); // 0

$buffered = new Channel(100);
echo $buffered->capacity(); // 100

Example #2 Adaptive logic based on channel type

<?php

use Async\Channel;

function processChannel(Channel $ch): void {
    if ($ch->capacity() === 0) {
        echo "Rendezvous channel: each send waits for a receiver\n";
    } else {
        echo "Buffered channel: capacity {$ch->capacity()}\n";
        echo "Free: " . ($ch->capacity() - $ch->count()) . " slots\n";
    }
}

See also