KomponentenCoroutine::isCancellationRequested

Coroutine::isCancellationRequested ​

(PHP 8.6+, True Async 1.0)

php
public Coroutine::isCancellationRequested(): bool

Prueft, ob ein Abbruch fuer die Coroutine angefordert wurde. Im Unterschied zu isCancelled() gibt diese Methode sofort nach dem Aufruf von cancel() true zurueck, auch wenn die Coroutine noch innerhalb von protect() ausgefuehrt wird.

Rueckgabewert ​

bool -- true, wenn ein Abbruch angefordert wurde.

Beispiele ​

Beispiel #1 Unterschied zu isCancelled() ​

php
<?php

use function Async\spawn;
use function Async\suspend;
use function Async\protect;

$coroutine = spawn(function() {
    protect(function() {
        suspend();
    });
});

suspend();

// Vor dem Abbruch
var_dump($coroutine->isCancellationRequested()); // bool(false)

$coroutine->cancel();

// Sofort nach cancel()
var_dump($coroutine->isCancellationRequested()); // bool(true)
var_dump($coroutine->isCancelled());             // bool(false) -- noch in protect()

Siehe auch ​