We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
杨老师您好 最近在学习owl项目,看到在闭包中引用yield true语句,这里似乎理解的不太明白,在以前的学习中一直理解为在使用yield关键字后的语句不会被立即执行,而是放入某个缓冲区,等待下一次在while 或者foreach调用时启用,这时多个代码块会并发执行,来达到协程效果,其在cpu级处于快速切换那什么实现..然后看到这里yield true表示不太理解,您若有时间敬请赐教哦,感激不尽
owl
yield true
yield
while
foreach
cpu
* $app->middleware(function($request, $response) { * $start = microtime(true); * * yield true; * * $use_time = (microtime(true) - $start) * 1000; * $response->withHeader('use-time', (int)$use_time.'ms'); * });
The text was updated successfully, but these errors were encountered:
这里并没有让代码并发执行,仅仅是一种跳出去再跳回来的跳转逻辑而已,算不上协程。 用yield实现并发的协程,语言要支持异步的IO或者计算才行,PHP在这一块的支持是很薄弱的。
对多个middleware的调用逻辑可以看\Owl\Middleware的execute()方法 (https://github.com/yeaha/owl-core/blob/master/src/Middleware.php#L69)
简单说明一下流程就是:
Sorry, something went wrong.
哇撒,谢谢杨老师 🎉
No branches or pull requests
杨老师您好
最近在学习
owl
项目,看到在闭包中引用yield true
语句,这里似乎理解的不太明白,在以前的学习中一直理解为在使用yield
关键字后的语句不会被立即执行,而是放入某个缓冲区,等待下一次在while
或者foreach
调用时启用,这时多个代码块会并发执行,来达到协程效果,其在cpu
级处于快速切换那什么实现..然后看到这里yield true
表示不太理解,您若有时间敬请赐教哦,感激不尽The text was updated successfully, but these errors were encountered: