Last active
January 25, 2019 19:55
-
-
Save iDVB/9aebf1fd49f732bb02f61458e48f81c1 to your computer and use it in GitHub Desktop.
async/await vs Promise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const doesKeyExist = async key => { | |
try{ | |
const data = await S3.headObject({ | |
Bucket: options.bucketName, | |
Key: key.replace(/^\/+/, ''), | |
}).promise(); | |
return true; | |
} | |
.catch(err => err.statusCode === 404 ? false : throw err); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const doesKeyExist = key => S3.headObject({ | |
Bucket: options.bucketName, | |
Key: key.replace(/^\/+/, '') | |
}) | |
.promise() | |
.then(data => true) | |
.catch(err => err.statusCode === 404 ? false : throw err); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment