Skip to content

Instantly share code, notes, and snippets.

@esperancaJS
Last active June 7, 2024 10:43
Show Gist options
  • Save esperancaJS/5fd9163f8447a0e8056405a3eb78c1fc to your computer and use it in GitHub Desktop.
Save esperancaJS/5fd9163f8447a0e8056405a3eb78c1fc to your computer and use it in GitHub Desktop.
Async .map .reduce
  const multipliedByTwo = await [1,2,3].reduce(async (accUnresolved, number, i) => {

    const accResolved = await accUnresolved;
    
    console.log(`working on number ${number}`);

    await new Promise(t => setTimeout(t, 1000));

    const multipliedNumber = number*2;

    return [
      ...accResolved,
      multipliedNumber
    ];
  }, []);
const workingBatch = await Promise.all(
        stockBatch.map(async (Code, i) => {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment