Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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