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";
    }
});

参见