Promiseからasync-awaitへの変換Promisefunction restaurantCustomer() { return getCustomer() .then(customer => { return getOrder(customer); }).then(order => { return prepareFood(order); }).then(meal => { return serveFood(meal); }).then(food => { return eatFood(food, customer); }).catch(showError); async/awaitasync function restaurantCustomer() { try{ let customer = await getCustomer(); let order = await getOrder(customer); let meal = await prepareFood(order); let food = await serveFood(meal); return await eatFood(food); } catch(e) { showError(e); } } 参考https://afteracademy.com/blog/migrating-from-promise-chains-to-async-await |
|