解决多个异步操作嵌套问题 祈雨的笔记 2019-01-07 JavaScript Promise 用Promise解决多个异步操作嵌套问题1234567891011121314151617181920let ansyFun = function(count, wait){ return new Promise((resolve, reject) => { setTimeout(() => { console.log(count, new Date()); resolve(count+1); }, wait); });}let promise = new Promise(function(resolve, reject) { resolve(1);});promise.then(data => { return ansyFun(data, 1000);}).then(data => { return ansyFun(data, 1000);}).then(data => { return ansyFun(data, 2000);}); 用Promise+async解决多个异步操作嵌套问题12345678910111213141516let ansyFun = function(count, wait){ return new Promise((resolve, reject) => { setTimeout(() => { console.log(count, new Date()); resolve(count+1); }, wait); });}async function asyncFun(){ let count = 1; count = await ansyFun(count, 1000); count = await ansyFun(count, 1000); count = await ansyFun(count, 2000);}asyncFun();