Skip to content

Instantly share code, notes, and snippets.

@unionx
Last active March 26, 2020 15:09
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 unionx/a40129735f849cdd8d52130c8bed7a4a to your computer and use it in GitHub Desktop.
Save unionx/a40129735f849cdd8d52130c8bed7a4a to your computer and use it in GitHub Desktop.
JS promise
function foo() {
let p = new Promise(function(resolve, reject) {
setTimeout(function() {
console.log('foo');
resolve('foo111');
}, 1000);
});
return p;
}
function bar() {
console.log('bar');
return 'bar111';
}
function foobar(x) {
console.log(x);
}
let out = foo()
.then(function() {
return bar();
})
.then(function(x) {
foobar(x);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment