When should I use crop and when to crop * with Koa.js

Looking through the kao samples, docs and middleware, I noticed that both forms yield

are being used without any specific difference that I noticed. The most extreme case is in koa-mount, where the sample code uses the form yield next;

and the package uses yield*

multiple times. Other packages ( koa-views , for example) also use a form yield next

.

I understand the difference between the two forms defined by the language, but don't understand how it goes in the koa context, they are used interchangeably and when is it correct to use one over the other.

EDIT 29/5

After some research, I realize that since koa is built on top of co and co is capable of handling multiple types of asynchronous results (thunks, Promises ...), it is possible that both are legal, but I'm still not sure if the guide helps to solve. what form to use in each scenario.

+3


source to share


1 answer


This article is yield next vs. yield * next from one of the koa team members explains what it is and why they use it.



There are several cases where one can use this yield *

, as the articles show, to avoid extra calls co

or preserve context ( this

) on execution. But then again, this is really unnecessary - as the author states, "we do not defend him to avoid confusion."

+6


source







All Articles