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

问题描述 投票:0回答:1

我有一个像这样的函数,使用PromisesNodeJS v6.10

function doSomeAsyncThings() {
    return this.doAsync().then((res) => {
        return this.logAsync().then(() => res)
    });
};

现在在上面的例子的背景下,this.logAsync()对我的应用程序并不重要,但更多用于记录保存目的。出于这个原因,我想知道我是否可以在后台执行此操作,因此没有等待或完成返回res

javascript node.js asynchronous es6-promise
1个回答
2
投票
function doSomeAsyncThings() {
    return this.doAsync().then(value => {
        this.logAsync()
        // do things with your `value`
    });
};

只是不要等待它。

© www.soinside.com 2019 - 2024. All rights reserved.