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

标签 javascript node.js asynchronous es6-promise

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

相关文章:

javascript - 如何在 durandal 中组织应用程序?

javascript - 如何在 Angular 5 中添加图像?

javascript - 暂停事件后,iOS 不执行异步或完整的 Javascript 代码(Cordova 应用程序)

asynchronous - 从 C# 调用非异步 Func<T> 返回 F# 函数中的启动 Async<T>?

python - 生成器函数和异步生成器函数的用途有什么区别

javascript - Sencha Architect 本地存储不工作

node.js - 了解 NodeJS 中 require 的行为

node.js - 如何在 mocha 的 mocha.opts 文件中添加 chaijs 的断言?

node.js - 如何在 Angular 6 中将联系表单详细信息发送到电子邮件?

asp.net-mvc - 如何判断 MVC AsyncController 线程是否在 ASP.NET 池或 I/O 完成端口中执行