从issue you linked 看来,我在answer to your previous question 中的第一个建议应该可行:为每个值导出一个promise。根据问题 cmets,看起来 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);
否则:
你说你不认为你可以使用顶级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 的更高版本)。