Node.js 等待在nodejs http中完成另一个get

Node.js 等待在nodejs http中完成另一个get,node.js,express,http,response,Node.js,Express,Http,Response,我需要通过http发送一个文件,然后报告任何错误。因此,我将我的基本express http服务器设置为: const-app=express(); app.get('/download',async(req,res)=>{ //发送一些大文件并记住所有错误 //在这个过程中会发生什么 常量错误列表=[]; somewaytopiethefile(res,filename) .on('error',error=>errorList.push(error)) .on('end',()=>repor

我需要通过http发送一个文件,然后报告任何错误。因此,我将我的基本express http服务器设置为:

const-app=express();
app.get('/download',async(req,res)=>{
//发送一些大文件并记住所有错误
//在这个过程中会发生什么
常量错误列表=[];
somewaytopiethefile(res,filename)
.on('error',error=>errorList.push(error))
.on('end',()=>reportThatFileWasSent());
...
});
app.get('/geterrors',(req,res)=>{
//但是我如何等待“/下载”路由呢
//从这里完成?
const errorList=waitUntilFileIsSent();
res.send(错误列表);
});

没关系,我已经解决了-只需添加回调

const completed=new Set();
const callbacks=newmap();
const errorList=新映射();
常数deleteTimeout=10*60*1000//10分钟
const callCallback=(令牌,回调)=>{
const errors=errorList.get(令牌);
errorList.delete(令牌);
回调(错误);
}
const holdErrors=(令牌)=>{
errorList.set(令牌,new set());
setTimeout(()=>errorList.delete(令牌),deleteTimeout);
}
const setError=(令牌,错误)=>{
如果(!errorList.has(令牌)){
errorList.set(令牌,new set());
setTimeout(()=>errorList.delete(令牌),deleteTimeout);
}
errorList.get(令牌).add(错误);
}
const oncompletion=(令牌、回调)=>{
如果(已完成。有(令牌)){
完成。删除(令牌);
callCallback(令牌,callCallback)
}
else if(errorList.has(令牌)){
callbacks.set(令牌、回调);
setTimeout(()=>callbacks.delete(令牌),deleteTimeout);
}
其他的
回调(未定义);//标记不正确
}
常量释放错误=(令牌)=>{
if(回调.has(令牌)){
const callback=callbacks.get(令牌);
回调。删除(令牌);
callCallback(令牌,回调);
}
否则{
完成。添加(令牌);
setTimeout(()=>completed.delete(令牌),deleteTimeout);
}
}
//////////////////////////////////////
app.get('/download',(req,res)=>{
...
holdErrors(请求查询令牌);
somewaytopiethefile(res,filename)
.on('error',error=>setError(toke,error))
.on('end',()=>releaseErrors(令牌));
})
app.get('/errors',(req,res)=>{
onCompletion(req.query.token,(errors)=>res.send(errors));
})