Skip to content

Instantly share code, notes, and snippets.

@karolk
Created September 28, 2020 20:03
Show Gist options
  • Save karolk/90aa00139e61abe67b069999a43b4a68 to your computer and use it in GitHub Desktop.
Save karolk/90aa00139e61abe67b069999a43b4a68 to your computer and use it in GitHub Desktop.
await vs. then

I recently run into a scenario highlighting that await is not always a drop-in, better replacement for then. Sometimes with then it's easier to control the scope of the function that runs after the promise is settled. I have a Redux middleware-inspired example here:

https://codesandbox.io/s/eager-wildflower-1kodv?file=/src/index.js

In example 2, the next call will only happen after the promise resolves.

In example 3, the next will be called immediately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment