Here is my code that throws the exception. Not able to figure out why it says 'Unexpected reserved word'. main() function is an async type. It isn't complaining for above line of code.
const { BlobServiceClient } = require("@azure/storage-blob");
async function main() {
try {
const blobServiceClient = await BlobServiceClient.fromConnectionString('some string');
let i = 1;
const result = await blobServiceClient.listContainers();
for await (const container of result) {
console.log(`Container ${i++}: ${container.name}`);
}
} catch (error) {
console.log(error);
}
}
main();
async and await Inside an async function, you can use the await keyword before a call to a function that returns a promise. This makes the code wait at that point until the promise is settled, at which point the fulfilled value of the promise is treated as a return value, or the rejected value is thrown.
Axios Request With Async/AwaitYou start by specifying the caller function as async . Then use the await keyword with the function call. Due to the await keyword, the asynchronous function pauses until the promise is resolved.
The word “async” before a function means one simple thing: a function always returns a promise. Other values are wrapped in a resolved promise automatically. For instance, this function returns a resolved promise with the result of 1 ; let's test it: async function f() { return 1; } f(). then(alert); // 1.
Your are getting this error because your Node version is lower than 10.0 and doesn't support for await...of
. As a side note, Turns out api does need itfor await
has no effect here and can be substituted for just for
added:
from the docs: you can either use for await of
if your runtime supports it, or iterate an iterable in an old-fashioned way
let containerItem = await result.next();
while (!containerItem.done) {
console.log(`Container ${i++}: ${containerItem.value.name}`);
containerItem = await iter.next();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With