Future::getCreatedLocation
(PHP 8.6+, True Async 1.0)
public function getCreatedLocation(): string
Restituisce informazioni sulla posizione di creazione del Future come stringa formattata. Comodo per il logging e l’output di debug.
Valore di ritorno
string — una stringa nel formato file:line, ad esempio /app/script.php:42.
Esempi
Esempio #1 Ottenere la posizione di creazione come stringa
<?php
use Async\Future;
$future = Future::completed("hello");
echo $future->getCreatedLocation(); // /app/script.php:5
Esempio #2 Utilizzo nei messaggi di debug
<?php
use Async\Future;
use Async\FutureState;
$state = new FutureState();
$future = new Future($state);
// Debug dei Future di lunga durata
\Async\async(function() use ($future) {
\Async\delay(5000);
if (!$future->isCompleted()) {
echo "Warning: Future created at "
. $future->getCreatedLocation()
. " has not completed in over 5 seconds\n";
}
});
Vedi anche
- Future::getCreatedFileAndLine — Posizione di creazione come array
- Future::getCompletedLocation — Posizione di completamento come stringa
- Future::getAwaitingInfo — Informazioni sulle coroutine in attesa