Skip to main content
se añadieron 150 caracteres en el cuerpo
Origen Enlace

Debes usar async y await en este caso.


function who() {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve('Prueba');
    }, 200);
  });
}

function what() {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve('de methodos');
    }, 300);
  });
}

function where() {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve('async await');
    }, 500);
  });
}

/*Sin async await*/
function test() {
  console.log("Entro a la funcion test");
  who()
  .then((response) => {
    console.log(`response who: ${response}`);
    console.log("Llamando a what");
    what()
    .then((response) => {
      console.log(`response what: ${response}`);
      console.log("Llamando a where");
      where()
      .then((response) => {
        console.log(`response where: ${response}`);
        console.log("termino");
      });
    });
  })
  console.log("ultima linea de la funcion test");
}

/* Con async/await */
async function msg() {
  const a = await who();
  const b = await what();
  const c = await where();

  console.log(`${return a[a, b, c]
}

async $function testing() { 
 b }const ${retorno c= }`await msg();
  const transformado = retorno.map(v => v.toUpperCase())
  console.log(transformado)
}

await testing()

Debes usar async y await en este caso.


function who() {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve('Prueba');
    }, 200);
  });
}

function what() {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve('de methodos');
    }, 300);
  });
}

function where() {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve('async await');
    }, 500);
  });
}

/*Sin async await*/
function test() {
  console.log("Entro a la funcion test");
  who()
  .then((response) => {
    console.log(`response who: ${response}`);
    console.log("Llamando a what");
    what()
    .then((response) => {
      console.log(`response what: ${response}`);
      console.log("Llamando a where");
      where()
      .then((response) => {
        console.log(`response where: ${response}`);
        console.log("termino");
      });
    });
  })
  console.log("ultima linea de la funcion test");
}

/* Con async/await */
async function msg() {
  const a = await who();
  const b = await what();
  const c = await where();

  console.log(`${ a } ${ b } ${ c }`);
}

Debes usar async y await en este caso.


function who() {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve('Prueba');
    }, 200);
  });
}

function what() {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve('de methodos');
    }, 300);
  });
}

function where() {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve('async await');
    }, 500);
  });
}

/*Sin async await*/
function test() {
  console.log("Entro a la funcion test");
  who()
  .then((response) => {
    console.log(`response who: ${response}`);
    console.log("Llamando a what");
    what()
    .then((response) => {
      console.log(`response what: ${response}`);
      console.log("Llamando a where");
      where()
      .then((response) => {
        console.log(`response where: ${response}`);
        console.log("termino");
      });
    });
  })
  console.log("ultima linea de la funcion test");
}

/* Con async/await */
async function msg() {
  const a = await who();
  const b = await what();
  const c = await where();

  return [a, b, c]
}

async function testing() { 
  const retorno = await msg()
  const transformado = retorno.map(v => v.toUpperCase())
  console.log(transformado)
}

await testing()
Agregados mas ejemplos
Origen Enlace

Debes usar async y await en este caso.

 
function who() {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve('Prueba');
    }, 200);
  });
}

function what() {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve('de methodos');
    }, 300);
  });
}

function where() {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve('async await');
    }, 500);
  });
}

/*Sin async await*/
function test() {
  console.log("Entro a la funcion test");
  who()
  .then((response) => {
    console.log(`response who: ${response}`);
    console.log("Llamando a what");
    what()
    .then((response) => {
      console.log(`response what: ${response}`);
      console.log("Llamando a where");
      where()
      .then((response) => {
        console.log(`response where: ${response}`);
        console.log("termino");
      });
    });
  })
  console.log("ultima linea de la funcion test");
}

/* Con async/await */
async function msg() {
  const a = await who();
  const b = await what();
  const c = await where();

  console.log(`${ a } ${ b } ${ c }`);
}
 

Debes usar async y await en este caso.

function who() {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve('Prueba');
    }, 200);
  });
}

function what() {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve('de methodos');
    }, 300);
  });
}

function where() {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve('async await');
    }, 500);
  });
}

async function msg() {
  const a = await who();
  const b = await what();
  const c = await where();

  console.log(`${ a } ${ b } ${ c }`);
}
 

Debes usar async y await en este caso.

 
function who() {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve('Prueba');
    }, 200);
  });
}

function what() {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve('de methodos');
    }, 300);
  });
}

function where() {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve('async await');
    }, 500);
  });
}

/*Sin async await*/
function test() {
  console.log("Entro a la funcion test");
  who()
  .then((response) => {
    console.log(`response who: ${response}`);
    console.log("Llamando a what");
    what()
    .then((response) => {
      console.log(`response what: ${response}`);
      console.log("Llamando a where");
      where()
      .then((response) => {
        console.log(`response where: ${response}`);
        console.log("termino");
      });
    });
  })
  console.log("ultima linea de la funcion test");
}

/* Con async/await */
async function msg() {
  const a = await who();
  const b = await what();
  const c = await where();

  console.log(`${ a } ${ b } ${ c }`);
}
Origen Enlace

Debes usar async y await en este caso.

function who() {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve('Prueba');
    }, 200);
  });
}

function what() {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve('de methodos');
    }, 300);
  });
}

function where() {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve('async await');
    }, 500);
  });
}

async function msg() {
  const a = await who();
  const b = await what();
  const c = await where();

  console.log(`${ a } ${ b } ${ c }`);
}