Skip to content

Instantly share code, notes, and snippets.

@ORESoftware
Created April 13, 2020 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ORESoftware/f5b82a7d931e20ee16ecc305a3e92fdd to your computer and use it in GitHub Desktop.
Save ORESoftware/f5b82a7d931e20ee16ecc305a3e92fdd to your computer and use it in GitHub Desktop.
async-await and outer scope changes

This problem:

let mightChange = {id:1}

const doWork = async v => {
  const result1 = await doSomethingWith(mightChange);
  const result2 = await doAnotherThingWith(mightChange);   // mightChange.id might be mutated
  return doSomething(result2)
};

is the same problem as:

const doWork = async (v,cb) => {
  doSomethingWith(mightChange, (err, v) => {
    doAnotherThingWith(mightChange, (err,v) => {   // mightChange.id might be mutated
      doSomething(v,cb)
    })
  });
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment