Skip to content

Instantly share code, notes, and snippets.

@dsernst
Last active January 26, 2016 11:40
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 dsernst/8b25d419a5195d72559a to your computer and use it in GitHub Desktop.
Save dsernst/8b25d419a5195d72559a to your computer and use it in GitHub Desktop.
Notes for a quick presentation to introduce other developers to Promises

Promises

Why?

  • reclaim simple synchronous control flow like return & throw
  • easier to write and maintain
  • banish callback hell

How?

  • gives each async call state: pending, fulfilled, rejected
  • lets you break up asynchronous nested callbacks into chained synchronous logic
  • use bluebird

Working with promises:

  • .then()
  • .catch() / .finally()
  • .props()
  • .map() / .reduce() / .filter()
  • .tap()
  • More convenience methods: .get(), .return(), .delay()

Turning into promises?

  • Promise.promisifyAll()
  • promisify()
  • resolve()
  • new Promise(function (resolve, reject) {})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment