Yield一石二鸟。它把值返回给了调用方,同时又从调用方拿回了新的输入。如图所示:
Coroutine object I
Coroutine继续执行的函数名总是相同的,例如”next“或者”resume“。这比”step1“或者”step2“来说表达力就差多了。我们可以把coroutine用object包装起来,这样代码看起来会好一些。
lua version: https://tio.run/
es2017 version: https://tio.run/
Yield一石二鸟。它把值返回给了调用方,同时又从调用方拿回了新的输入。如图所示:
Coroutine object I
Coroutine继续执行的函数名总是相同的,例如”next“或者”resume“。这比”step1“或者”step2“来说表达力就差多了。我们可以把coroutine用object包装起来,这样代码看起来会好一些。
lua version: https://tio.run/
es2017 version: https://tio.run/