我有一个类似这样的函数,使用Promises
和NodeJS v6.10
:
function doSomeAsyncThings() {
return this.doAsync().then((res) => {
return this.logAsync().then(() => res)
});
};
现在,在上面示例的上下文中,this.logAsync()
对我的应用程序并不重要,但更多的是用于记录保存目的。因此,我想知道是否可以在后台执行此操作,从而不等待或其完成返回 res
?
最佳答案
function doSomeAsyncThings() {
return this.doAsync().then(value => {
this.logAsync()
// do things with your `value`
});
};
不要等待。
关于javascript - 如何使用 Promises 执行后台异步任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48810046/