从您链接的问题来看,我对您上一个问题的回答中的第一个建议似乎应该有效:为每个值导出一个承诺。根据问题评论,Pulumi 似乎理解导出的承诺。
async function go() {
...
const awsIdentity = await aws.getCallerIdentity({ async: true });
const accountId = awsIdentity.accountId;
...
return {
dnsZoneName: DNSZone.name,
BucketID: Bucket.id,
dbHardURL: DBHost.publicDns,
devDbURL: publicDbAddress.fqdn,
};
}
const goPromise = go();
goPromise.catch(error => {
// Report the error. Note that since we don't chain on this, it doesn't
// prevent the exports below from rejecting (so Pulumi will see the error too,
// which seems best).
});
export const dnsZoneName = goPromise.then(res => res.DNSZone.name);
export const BucketID = goPromise.then(res => res.Bucket.id);
export const dbHardURL = goPromise.then(res => res.DBHost.publicDns);
export const devDbURL = goPromise.then(res => res.publicDbAddress.fqdn);
否则:
你说你不认为你可以使用 top-level await
,但你没有说为什么。
如果只是您在弄清楚如何使用它时遇到问题,您可以按照提供的方式进行操作aws.getCallerIdentity
,并且代码示例的“...”中的任何内容都提供了承诺:
const awsIdentity = await aws.getCallerIdentity({ async: true });
const accountId = awsIdentity.accountId;
// ...
export const dnsZoneName = DNSZone.name;
export const BucketID = Bucket.id;
export const dbHardURL = DBHost.publicDns;
export const devDbURL = publicDbAddress.fqdn;
或者,如果您需要将具有这些属性的对象作为默认导出导出:
const awsIdentity = await aws.getCallerIdentity({ async: true });
const accountId = awsIdentity.accountId;
// ...
export default {
dnsZoneName: DNSZone.name
BucketID: Bucket.id
dbHardURL: DBHost.publicDns
devDbURL: publicDbAddress.fqdn
};
请注意,在这两种情况下,代码都不在任何函数内,而是在模块的顶层。
使用 Node.js v13 和 v14(到目前为止),您需要--harmony-top-level-await
运行时标志。我的猜测是它不会落后于 v15 的标志(甚至可能只是 v14 的更高版本)。