root_context

(PHP 8.6+, True Async 1.0)

root_context() — Devuelve el objeto Async\Context raíz global, compartido en toda la solicitud.

Descripción

root_context(): Async\Context

Devuelve el contexto de nivel superior. Los valores establecidos aquí son visibles a través de find() desde cualquier contexto en la jerarquía.

Valores de retorno

Un objeto Async\Context.

Ejemplos

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

// Establecer configuración global
root_context()
    ->set('app_name', 'MyApp')
    ->set('environment', 'production');

spawn(function() {
    // Accesible desde cualquier corrutina mediante find()
    $env = current_context()->find('environment'); // "production"
});
?>

Ver también