Last active
October 24, 2017 08:38
-
-
Save ktanaka117/82fd0ec957022b1c97aee0e7a84d8f54 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 = params => { | |
return new Promise((resolve, reject) => { | |
sleep(() => { resolve(params) }) | |
}) | |
} | |
const isValidParams = params => { | |
if (!params.id) { | |
return false | |
} | |
return true | |
} | |
const searchPriceById = id => { | |
return new Promise((resolve, reject) => { | |
sleep(() => { resolve(1000) }) | |
}) | |
} | |
const getPrice = response({ 'id': 'abc123' }) | |
.then(params => { | |
if (!isValidParams(params)) { | |
throw new Error('"id" must be included to params.') | |
} | |
return searchPriceById(params.id) | |
}) | |
.then(itemPrice => { | |
console.log(itemPrice) | |
}) | |
.catch(err => { | |
console.log(err) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment