August 4th, 2018
I am helping on a Gatsbyjs plugin to pull in for example a photo from instagram with the instagram oembed api. I am working on a function.
Refactor fetchOembedProviders and fetchOembed to use async / await
Remove the use of .then() and use async/await instead on the fetchOembedProviders and fetchOembed functions in the helper.js file.
How To Use Async Await in a function?
To Use ‘await’ I need to mark the function with ‘async’ so that inside that function I can ‘await’ values. Says Wes Bes, at least that is what I am hearing from Wes Bos video 69 on es6 (buy the Wes Bos es6 video course here for $139)
I did not know where in the function to put the ‘async’ so I just tried out a couple of things. Here is one thing I tried, to wrap the function in an ‘ola’ function and let that ‘ola’ function be ‘async’. Then inside that ‘ola’ function I can ‘await’ values.
What if I wrap the function in an ‘ola’ function to Use Async Await?
- where does the ‘async’ go?
- where does the ‘await’ go?