Skip to content

Instantly share code, notes, and snippets.

@emilioriosvz
Last active May 10, 2018 07:32
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 emilioriosvz/6105f60590bc541d5bc7c9089165823f to your computer and use it in GitHub Desktop.
Save emilioriosvz/6105f60590bc541d5bc7c9089165823f to your computer and use it in GitHub Desktop.
Simple example to understand async await

RUN

npx https://gist.github.com/emilioriosvz/6105f60590bc541d5bc7c9089165823f

#!/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')
{"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