Skip to content

Instantly share code, notes, and snippets.

@emilioriosvz
Last active May 10, 2018 07:32
Show Gist options
  • 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