美文网首页
协程调度器Coroutine\Scheduler

协程调度器Coroutine\Scheduler

作者: 枫叶鱼水 | 来源:发表于2019-08-13 09:50 被阅读0次

协程调度器类,4.4版本后推荐使用Coroutine\Scheduler作为cli script模式的编码风格。

新增Swoole\Coroutine\Scheduler调度器类作为cli命令行脚本的入口,取代go() + Swoole\Event::wait()的方式

增加Swoole\Coroutine\Run函数,提供对Swoole\Coroutine\Scheduler的封装

新的方式

$scheduler=newCoroutine\Scheduler;$scheduler->add(function() {Co::sleep(1);echo"Done.\n";});$scheduler->start();

或者:

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

旧的方式 (将废弃)

go(function() {Co::sleep(1);echo"Done.\n";});Swoole\Event::wait();

相关文章

网友评论

      本文标题:协程调度器Coroutine\Scheduler

      本文链接:https://www.haomeiwen.com/subject/yttvjctx.html