V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
V2EX  ›  islxyqwe  ›  全部回复第 3 页 / 共 3 页
回复总数  41
1  2  3  
2019 年 10 月 12 日
回复了 lqzhgood 创建的主题 Node.js 请教一个 Promise 递归的最佳实践(内存释放)
怎么又是 new promise 又是 async 的, async 就是返回 promise 的语法啊
递归的话肯定要尾递归的,我觉得这么写就行了
let loading = false;
(async () => {
if (loading) return;
loading = true;
await getAll();
loading = false;
})()

async function getAll(page = 1) {
const body = await getPage(page);
bigHandle(body); //body 很大 处理完需要及时释放掉
if (page < 10) {
return getAll(++page)
}
}
1  2  3  
About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2895 Online   Highest 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 10ms · UTC 03:29 · PVG 11:29 · LAX 20:29 · JFK 23:29
♥ Do have faith in what you're doing.