coroutine_context
(PHP 8.6+, True Async 1.0)
coroutine_context() — Devuelve el objeto Async\Context vinculado a la corrutina actual.
Descripción
coroutine_context(): Async\Context
Devuelve el contexto privado de la corrutina actual. Los datos establecidos aquí no son visibles para otras corrutinas. Si el contexto para la corrutina aún no se ha creado, se crea automáticamente.
Valores de retorno
Un objeto Async\Context.
Ejemplos
<?php
use function Async\spawn;
use function Async\coroutine_context;
spawn(function() {
coroutine_context()->set('step', 1);
// Más adelante en la misma corrutina
$step = coroutine_context()->getLocal('step'); // 1
});
spawn(function() {
// No puede ver 'step' de otra corrutina
$step = coroutine_context()->findLocal('step'); // null
});
?>
Ver también
- current_context() — Contexto del Scope
- root_context() — Contexto global
- Context — El concepto de contexto