How do you understand the principle of encapsulating next in node?

  node.js, question

function co(GenFunc) {
return function(cb) {
var gen = GenFunc()
next()
function next() {
if (gen.next) {
var ret = gen.next()
If (ret.done) {// if finished, execute cb
cb && cb()
Else {//continue next
ret.value(next)
bracket
bracket
bracket
bracket
bracket
Beginners koa, tj great god co library core code as above, it is difficult for me to understand ret.value(next) it just passed the next function body to ret object’s value attribute, how can you execute next () again (my understanding is that the whole function only executed once gen.next (), no recursion) please answer questions and answer questions, thank you very much!

I wrote an article on the principles of koa middleware a few days ago, hoping to help you understand a little bit.Generator Exploration (1)-Analysis of KOA Middleware Mechanism
(PS: The implementation of KOA inside next is actually not co, but a function called compose)