【发布时间】:2021-07-19 11:56:39
【问题描述】:
如果它不存在,我正在尝试使用以下逻辑创建一个谷歌存储桶:
async function createBucket(id){
const bucket = storage.bucket("bucket-" + id);
const exists = await bucket.exists();
if (!exists) {
console.log("creating bucket>>" + "bucket-" + id);
try {
await bucket.create();
} catch (e) {
console.error("error in creating bucket>>>", e);
}
} else {
console.log("it already exists >>" + exists);
}
}
奇怪的是,我看到的是it already exists >> false,而我应该只能看到it already exists >> true 或creating bucket>>bucket-123。任何解决此问题的帮助将不胜感激。谢谢!
【问题讨论】:
-
storage是如何初始化的?为什么不使用承诺 bucket.exits.then(... -
这可能会受到竞争条件的影响。
-
storage.bucket("bucket-" + id);也是异步调用吗?如果你写await storage.bucket("bucket-" + id);会发生什么?
标签: node.js google-api-nodejs-client