Coroutine::asHiPriority

(PHP 8.6+, True Async 1.0)

public Coroutine::asHiPriority(): Coroutine

Marks the coroutine as high-priority. The scheduler will give preference to such coroutines when selecting the next task for execution.

The method returns the same coroutine object, enabling a fluent interface.

Return Value

Coroutine – the same coroutine object (fluent interface).

Examples

Example #1 Setting priority

<?php

use function Async\spawn;

$coroutine = spawn(function() {
    return "important task";
})->asHiPriority();

Example #2 Fluent interface

<?php

use function Async\spawn;
use function Async\await;

$result = await(
    spawn(fn() => criticalOperation())->asHiPriority()
);

See Also