Skip to content

Instantly share code, notes, and snippets.

@kurtroberts
Created November 12, 2017 02:14
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 kurtroberts/3322db46c99cef6d18e050ff3b22350c to your computer and use it in GitHub Desktop.
Save kurtroberts/3322db46c99cef6d18e050ff3b22350c to your computer and use it in GitHub Desktop.
One-stop understanding of Promises...
//TL;DR - Read the MDN page and skip all the tutorials:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
//ES6
var x = new Promise((resolve, reject) => {
setTimeout(function () { resolve('test'); }, 5000);
});
x.then((msg) => console.log(msg));
//result - after 5 seconds, writes 'test' to STDOUT and exits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment