Future::getCreatedLocation
(PHP 8.6+, True Async 1.0)
public function getCreatedLocation(): string
以格式化字符串的形式返回 Future 创建位置的信息。便于日志记录和调试输出。
返回值
string — 格式为 file:line 的字符串,例如 /app/script.php:42。
示例
示例 #1 获取字符串形式的创建位置
<?php
use Async\Future;
$future = Future::completed("hello");
echo $future->getCreatedLocation(); // /app/script.php:5
示例 #2 在调试消息中使用
<?php
use Async\Future;
use Async\FutureState;
$state = new FutureState();
$future = new Future($state);
// Debug long-running Futures
\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";
}
});
参见
- Future::getCreatedFileAndLine — 创建位置(数组形式)
- Future::getCompletedLocation — 完成位置(字符串形式)
- Future::getAwaitingInfo — 等待者信息