热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

同步使用已解决的承诺数据

如何解决《同步使用已解决的承诺数据》经验,您有什么比较好的解决方法?

我正在学习承诺,因此我绝对希望在继续之前先了解它们的用法。我正在使用在线服务库,该库具有返回承诺的功能。

我读过的几乎所有示例都在链接then()函数中使用了已解析的数据

const result = Library.functionReturningAPromise()
result.then(function(res) {
    const obj = new Example(res)
    return obj
}).then(function(ob) {
    // do the rest of the logic within these then() functions
})

或在async函数中使用解析的数据

async function test() {
    const result = await Library.functionReturningAPromise()
    const obj = new Example(result)

    // do the rest of the logic
}

我想知道是否有任何方法可以使用“正常”同步代码中已解决的承诺中的数据

 const result = Library.functionReturningAPromise()

 // do something to resolve the promise

 const obj = new Example(result)

或者,如果您需要始终“包装” 使用函数中已解决的承诺中的数据的所有逻辑async


推荐阅读
author-avatar
暗恋达志_227
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有