O'Reilly logo
  • Dilip Kushwaha thinks this is interesting:

function spiderLinks(currentUrl, body, nesting) { let promise = Promise.resolve(); if(nesting === 0) { return promise; } const links = utilities.getPageLinks(currentUrl, body); links.forEach(link => { promise = promise.then(() => spider(link, nesting - 1)); }); return promise; }

From

Cover of Node.js Design Patterns - Second Edition

Note

chain of promises aka MAGIC