Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Define an async function

const yourAsyncFunction = async () => {
    // do something asynchronously and return a promise
    return result;
  }
  
anArray.forEach(async item => {
   // do something asynchronously for each item in 'anArray'
   // one could also use .map here to return an array of promises to use with 'Promise.all()'
 });
 
server.getPeople().then(async people => {
  people.forEach(person => {
    // do something asynchronously for each person
  });
});
Source by www.theodinproject.com #
 
PREVIOUS NEXT
Tagged: #Define #async #function
ADD COMMENT
Topic
Name
3+9 =