Answers for "js use await"

9

how to make an async function

function resolveAfter2Seconds() {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve('resolved');
    }, 2000);
  });
}

//async function:
async function asyncCall() {
  console.log('calling');
  const result = await resolveAfter2Seconds();
  console.log(result);
  // expected output: 'resolved'
}

asyncCall();
Posted by: Guest on March-03-2020
3

await javascript

If the value of the expression following the await operator is not a Promise, it's converted to a resolved Promise.
Posted by: Guest on April-14-2021
3

async

function resolveAfter2Seconds() {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve('resolved');
    }, 2000);
  });
}

async function asyncCall() {
  console.log('calling');
  const result = await resolveAfter2Seconds();
  console.log(result);
  // expected output: 'resolved'
}

asyncCall();
Posted by: Guest on May-29-2020
0

await javascript

The await operator is used to wait for a Promise. It can only be used inside an async function within regular JavaScript code; however it can be used on its own with JavaScript modules.
Posted by: Guest on April-14-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language