Skip to content

Instantly share code, notes, and snippets.

@ktanaka117
Last active October 24, 2017 08:37
Show Gist options
  • Save ktanaka117/27890ed9146d58e0444059db7275cab4 to your computer and use it in GitHub Desktop.
Save ktanaka117/27890ed9146d58e0444059db7275cab4 to your computer and use it in GitHub Desktop.
'use strict'
const sleep = someFunction => {
return new Promise(resolve => {
setTimeout(() => {
resolve(someFunction())
}, 5000)
})
}
const response = async params => {
return await sleep(() => { return params })
}
const isValidParams = params => {
if (!params.id) {
return false
}
return true
}
const searchPriceById = async id => {
return await sleep(() => { return 1000 })
}
const getPrice = async () => {
const resp = await response({ 'id': 'abc123' })
if (!isValidParams(resp)) {
throw new Error('"id" must be included to params.')
}
const itemPrice = await searchPriceById(resp.id)
console.log(itemPrice)
}
getPrice().catch(error => {
console.log(error)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment