OpenSwoole\Coroutine\Channel->close()

Latest version: pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5

Declaration

<?php OpenSwoole\Coroutine\Channel->close(): bool

Parameters

None

Return

A bool will be returned, true for a successful close.

OpenSwoole Coroutine Channel Close

Description

Close the channel and resume other Coroutines.

Example

<?php
co::run(function() {

    $data = 'Hello World!';

    $chan = new chan(1);
    $chan->push($data);
    $pop = $chan->pop();

    var_dump($pop);

    $chan->close();

});

Notes

By closing a channel it will wake up all the suspended coroutines, any push() calls will return false and so will any pop() calls.

Waking up all the coroutines waiting to read and write to the channel.

Last updated on September 1, 2022