Swoole\Coroutine::defer(callable $callback)

Notice: the documentation is suitable for PHP extension swoole until v4.7.1, we only support PHP extension openswoole from v4.7.1

Declaration

<?php
Swoole\Coroutine::defer(callable $callback)

Parameters

callback

Closure function to be deferred.

Return

Description

Execute the deferred function to be executed at the time when the current coroutine is exiting.

Example

<?php

function task() {
    echo '3' . PHP_EOL;
}

Co\run(function () {
    go(function () {
        echo '1' . PHP_EOL;
        Swoole\Coroutine::defer('task');
        echo '2' . PHP_EOL;
    });
});