Swoole Coroutine Scheduler and Co\run

Swoole\Coroutine\Scheduler and Co\run

Swoole Scheduler is designed to replace the patten go() + Swoole\Event::wait() as a context for executing coroutines outside server.

Co\run is the alias of Swoole\Coroutine\run.

Example:

<?php

# multiple conexts

$run = new Swoole\Coroutine\Scheduler;

$run->add(function () {
    Co::sleep(1);
    echo "Done 1.\n";
});
$run->add(function () {
    Co::sleep(1);
    echo "Done 2.\n";
});
$run->start();

# or

Co\run(function() {
    Co::sleep(1);
    echo "Done.\n";
});

Depreciation Example:

<?php
go(function () {
    Co::sleep(1);
    echo "Done.\n";
});

Swoole\Event::wait();