phasync
phasync / yield

Method

phasync::yield

Suspends the current coroutine until the loop has made its next round, after the coroutines that were ready have run.

Description#

public static phasync::yield(): void

Like sleep(0), it lets the others run, but it resumes after the coroutines that called sleep(0) in the same round. It returns at once outside a coroutine.

Examples#

Example 1
phasync::run(function () {
    phasync::go(function () { phasync::yield(); echo "yielded\n"; });
    phasync::go(function () { phasync::sleep(); echo "slept\n"; });
});   // slept, yielded

See also#

  • phasync::sleepPauses the current coroutine for $seconds, and lets the others run meanwhile.