# wait
~~~
void Warriorman\Coroutine::wait()
~~~
协程调度,只有使用这个方法之后,协程定时器、Channel模块才会生效。
## 注意
wait方法会阻塞当前代码,只有当wait之前所有协程和定时器运行完毕,程序才会继续向下执行
如果在Worker环境下,不需要再使用wait方法。
### 例子
```
<?php
use Warriorman\Coroutine;
/**
* 展示协程切换
*/
$arr[] = Coroutine::create(function () {
var_dump(Coroutine::getCid() . " start");
Coroutine::yield();
var_dump(Coroutine::getCid() . " end");
});
$arr[] = Coroutine::create(function () {
var_dump(Coroutine::getCid() . " start");
Coroutine::yield();
var_dump(Coroutine::getCid() . " end");
});
foreach ($arr as $n) {
Coroutine::resume($n);
}
Coroutine::wait();
```
- 序言
- 启动停止
- 简单的开发示例
- 性能测试
- 性能测试-数据库
- 通讯协议
- Coroutine类
- create
- getCid
- yield
- resume
- sleep
- wait
- getTotalNum
- isExist
- defer
- Runtime类
- Worker类
- 构造函数
- 属性
- workerId
- id
- name
- protocol
- transport
- reusePort
- backlog
- connections
- stdoutFile
- pidFile
- logFile
- user
- reloadable
- daemonize
- globalEvent
- 回调属性
- onWorkerStart
- onWorkerReload
- onConnect
- onMessage
- onClose
- onBufferFull
- onBufferDrain
- onError
- 方法
- rename
- runAll
- stopAll
- listen
- TcpConnection类
- 属性
- id
- protocol
- worker
- maxSendBufferSize
- defaultMaxSendBufferSize
- defaultMaxPackageSize
- 方法
- set
- send
- getRemoteIp
- getRemotePort
- close
- destroy
- pauseRecv
- resumeRecv
- pipe
- Timer定时器类
- add
- del
- 定时器注意事项
- Channel类
- 构造方法
- push
- pop
- length
- isEmpty()