【问题标题】:Dealing with async code in the aws-cdk in typescript在 typescript 中处理 aws-cdk 中的异步代码
【发布时间】:2020-07-01 03:53:18
【问题描述】:

使用带有 aws-cdk 的 typescript 中的异步代码,有没有人有一个很好的方法/模式来处理解决承诺,以及app.syth()? 我能想到的最好的是:

const promise = new PipelineStack(app, 'pipeline', config)
if (promise){
    promise.resolve(foo =>
        app.synth()
    )
} else {
    app.synth()
}

如果可以的话,我会做同步

【问题讨论】:

  • 我最终只返回了一个空白承诺,例如:await prom.then( results=> { console.log(results) app.synth() })

标签: typescript asynchronous async-await aws-cdk


【解决方案1】:

您可以将代码简化为以下代码。

new PipelineStack(app, 'pipeline', config).then(
    foo => app.synth(),
    error => console.log(error)
);

您无需兑现承诺。只需处理解析的值(foo)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-01-02
    • 2021-04-10
    • 2023-01-13
    • 2019-03-12
    • 1970-01-01
    • 2018-10-03
    • 2016-11-10
    • 2017-10-15
    相关资源
    最近更新 更多