根据文档的描述,ctx.runInBackground不阻塞当前请求的意思是这个方法里面包含的内容是异步执行么,通过观察线上的日志发现没有异步执行,还是同步的。
How To ReproduceSteps to reproduce the behavior:
我修改了程序,按照文档示例编写了自己的代码console.log(1);
const request = {};
const config = await ctx.service.api.do1(request);
console.log(2)
// 下单后需要进行一次核对,且不阻塞当前请求
ctx.runInBackground(async () => {
// 这里面的异常都会统统被 Backgroud 捕获掉,并打印错误日志
await ctx.service.api.do2(request);
console.log(3)
});
console.log(4)
ctx.body = {ok:true}
控制台输出: 1 2 3 4
Expected behavior 1 2 4 3
Context Node Version:v10.15.3 Egg Version:v2.15.1 Plugin Name:none Plugin Version:none Platform:centos7.1