问题描述
快速问题...
在 README of editly 之后,我在像这样编辑后成功创建了视频:
// create video
editly(editSpec)
.catch(console.error);
很遗憾,我使用 Expressjs 来执行此操作,并且需要在视频创建完成后发回响应。
但是,当我尝试使用 .then 提取任何值时,它返回 undefined:
// create video
editly(editSpec)
.then(r => {
console.log(`Is this undefined? Probably yes! r: `,r)
res.json(r)
})
.catch(console.error);
我怎样才能做到这一点?
解决方法
对于那些在 ExpressJS 的上下文中试图等待 editly 返回值的人,这里是我解决这个问题的方法:
// create video via Promise.all
Promise.all([
editly(editSpec).catch(e => { return e } )
])
.then(r => {
console.log(`r: `,r) // still returns undefined but its ok now! [ undefined ]
res.json({message: "complete"})
})