es6 async arrow function code example
Example 1: async arrow function
const foo = async () => {
}
Example 2: async await promise all javascript
let characterResponse = await fetch('http://swapi.co/api/people/2/')
let characterResponseJson = await characterResponse.json()
let films = await Promise.all(
characterResponseJson.films.map(async filmUrl => {
let filmResponse = await fetch(filmUrl)
return filmResponse.json()
})
)
console.log(films)
Example 3: javascript async await arrow function
Async arrow functions look like this:
const foo = async () => {
}
Async arrow functions look like this for a single argument passed to it:
const foo = async evt => {
}
Async arrow functions look like this for multiple arguments passed to it:
const foo = async (evt, callback) => {
}
The anonymous form works as well:
const foo = async function() {
}
An async function declaration looks like this:
async function foo() {
}
Using async function in a callback:
const foo = event.onCall(async () => {
})
Example 4: async await arrow function
YourAsyncFunctionName = async (value) => {
}