current_context

(PHP 8.6+, True Async 1.0)

current_context() — 현재 Scope에 바인딩된 Async\Context 객체를 반환합니다.

설명

current_context(): Async\Context

현재 Scope의 컨텍스트가 아직 생성되지 않은 경우 자동으로 생성됩니다. 이 컨텍스트에 설정된 값은 find()를 통해 현재 Scope의 모든 코루틴에서 볼 수 있습니다.

반환 값

Async\Context 객체입니다.

예제

<?php
use function Async\current_context;
use function Async\spawn;

current_context()->set('request_id', 'abc-123');

spawn(function() {
    // 부모 스코프의 값을 볼 수 있습니다
    $id = current_context()->find('request_id'); // "abc-123"
});
?>

같이 보기