在koa里面写中间件,格式是这样:
module.exports = function(opts){
return function *(next){
yield next;
}
}
每次接收到请求都会走一遍return的生成器函数
但是我现在想在生成器函数外面,也就是在启动程序的时候执行其他生成器函数,请问怎么做?
就是下面这样,在程序加载的时候执行yield test();而不是在return function *(){}里面每次用户请求时执行
module.exports = function(opts){
return function *(next){
yield next;
}
function *test(){
....
}
}