Channel::isFull
(PHP 8.6+, True Async 1.0)
public Channel::isFull(): bool
Verifica se il buffer del canale e’ riempito alla capacita’ massima.
Per un canale rendezvous (capacity = 0), restituisce sempre true,
poiche’ non c’e’ un buffer.
Valori di ritorno
true — il buffer e’ pieno (oppure e’ un canale rendezvous).
false — il buffer ha spazio libero.
Esempi
Esempio #1 Verifica del riempimento del buffer
<?php
use Async\Channel;
$channel = new Channel(2);
echo $channel->isFull() ? "pieno" : "ha spazio"; // "ha spazio"
$channel->send('a');
$channel->send('b');
echo $channel->isFull() ? "pieno" : "ha spazio"; // "pieno"
Esempio #2 Velocita’ di invio adattiva
<?php
use Async\Channel;
$channel = new Channel(50);
spawn(function() use ($channel) {
foreach (readLargeFile('data.csv') as $line) {
if ($channel->isFull()) {
echo "Buffer pieno, rallentamento dell'elaborazione\n";
}
$channel->send($line); // si sospende se pieno
}
$channel->close();
});
Vedi anche
- Channel::isEmpty — Verifica se il buffer e’ vuoto
- Channel::capacity — Capacita’ del canale
- Channel::count — Numero di valori nel buffer
- Channel::sendAsync — Invio non bloccante