Last active
October 24, 2017 08:37
-
-
Save ktanaka117/27890ed9146d58e0444059db7275cab4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
'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