gpt4 book ai didi

javascript - 如何使用 Promises 执行后台异步任务

转载 作者:行者123 更新时间:2023-12-01 02:25:53 25 4
gpt4 key购买 nike

我有一个类似这样的函数,使用PromisesNodeJS 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com