Future::getCompletedLocation

(PHP 8.6+, True Async 1.0)

public function getCompletedLocation(): string

Returns information about the Future completion location as a formatted string. Convenient for logging and debugging.

Return value

string — a string in the format file:line, for example /app/worker.php:15. If the Future has not yet completed, returns an empty string.

Examples

Example #1 Getting the completion location as a string

<?php

use Async\Future;
use Async\FutureState;

$state = new FutureState();
$future = new Future($state);

$state->complete("result");

echo $future->getCompletedLocation(); // /app/script.php:9

Example #2 Full Future lifecycle tracing

<?php

use Async\Future;
use Async\FutureState;

$state = new FutureState();
$future = new Future($state);

\Async\async(function() use ($state) {
    \Async\delay(50);
    $state->complete("done");
});

$result = $future->await();

echo "Future lifecycle:\n";
echo "  Created at:   " . $future->getCreatedLocation() . "\n";
echo "  Completed at: " . $future->getCompletedLocation() . "\n";
echo "  Result:       " . $result . "\n";

See also