同步阅读进度,多语言翻译,过滤屏幕蓝光,评论分享,更多完整功能,更好读书体验,试试 阅读 ‧ 电子书库
wait
There is a way of making sure the script doesn't finish before alice does: the built-in command wait. Without arguments, wait simply waits until all background jobs have finished. So to make sure the above code behaves properly, we would add wait, like this:
alice &
hatter
wait
Here, if hatter finishes first, the parent shell will wait for alice to finish before finishing itself.
If your script has more than one background job and you need to wait for specific ones to finish, you can give wait the process ID of the job.
However, you will probably find that wait without arguments suffices for all coroutines you will ever program. Situations in which you would need to wait for specific background jobs are quite complex and beyond the scope of this book.
请支持我们,让我们可以支付服务器费用。
使用微信支付打赏
