npx https://gist.github.com/emilioriosvz/6105f60590bc541d5bc7c9089165823f
Last active
May 10, 2018 07:32
-
-
Save emilioriosvz/6105f60590bc541d5bc7c9089165823f to your computer and use it in GitHub Desktop.
Simple example to understand async await
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
const getName = name => { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
resolve(name) | |
}, 500) | |
}) | |
} | |
const fullName = (name, surname) => { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
resolve(`${name} ${surname}`) | |
}, 1000) | |
}) | |
} | |
const greater = async (name, surname) => { | |
var n = await getName(name) | |
var fname = await fullName(n, surname) | |
console.log('hello', fname) | |
} | |
greater('Emilio', 'R') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"name": "npx-example", "version": "0.0.0", "bin": "./asyncGreater.js"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment