current_context
(PHP 8.6+, True Async 1.0)
current_context() — Gibt das an den aktuellen Scope gebundene Async\Context-Objekt zurueck.
Beschreibung
php
current_context(): Async\ContextWenn der Kontext fuer den aktuellen Scope noch nicht erstellt wurde, wird er automatisch erstellt. In diesem Kontext gesetzte Werte sind fuer alle Coroutinen im aktuellen Scope ueber find() sichtbar.
Rueckgabewerte
Ein Async\Context-Objekt.
Beispiele
php
<?php
use function Async\current_context;
use function Async\spawn;
current_context()->set('request_id', 'abc-123');
spawn(function() {
// Sieht den Wert aus dem uebergeordneten Scope
$id = current_context()->find('request_id'); // "abc-123"
});
?>Siehe auch
- coroutine_context() — Coroutine-Kontext
- root_context() — globaler Kontext
- Context — das Kontext-Konzept