getData(function(data){ getMoreData(data, function(moreData){ getMoreMoreData(moreData, function(moreMoreData){ // ... }); }); });
改为以下代码:
getData() .then(function(data){ return getMoreData(data); }) .then(function(moreData){ return getMoreMoreData(moreData); }) .then(function(moreMoreData){ // ... }) .catch(function(error){ // 错误处理 });
getData(function(data){ getMoreData(data, function(moreData){ getMoreMoreData(moreData, function(moreMoreData){ // ... }); }); });
改为以下代码:
async function getDataAsync() { const data = await getData(); const moreData = await getMoreData(data); const moreMoreData = await getMoreMoreData(moreData); // ... }
getDataAsync().catch(function(error){ // 错误处理 });
上一篇:避免嵌套管道
下一篇:避免嵌套函数,谷歌云函数