Giter VIP home page Giter VIP logo

Comments (2)

yeaha avatar yeaha commented on August 30, 2024

这里并没有让代码并发执行,仅仅是一种跳出去再跳回来的跳转逻辑而已,算不上协程。
用yield实现并发的协程,语言要支持异步的IO或者计算才行,PHP在这一块的支持是很薄弱的。

对多个middleware的调用逻辑可以看\Owl\Middleware的execute()方法 (https://github.com/yeaha/owl-core/blob/master/src/Middleware.php#L69)

简单说明一下流程就是:

  1. 依次call每个middleware function
  2. 观察返回值是否一个Generator对象,因为允许middleware执行一次完事,不用再跳进去
  3. 调用Generator::current()检查返回值,如果是false说明这个middleware逻辑决定中断整个链条继续执行
  4. 把拿到的Generator放到一个先进后出的栈里
  5. 所有middleware执行完之后,把依次调用栈里的Generator::next()方法执行每个middleware剩余逻辑

from owl.

m9rco avatar m9rco commented on August 30, 2024

哇撒,谢谢杨老师 🎉

from owl.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.