



To use request with promises, install it like this: npm install requestĪnd then require("request-promise-native") in your code, like in the example above. Return new Promise(resolve => setTimeout(resolve, millis)) Ĭonst urls = await fetchUrls(INITIAL_URL) The sleep function is pretty straightforward: async function sleep(millis) millis - how long to sleep in milliseconds Much better, isn't it? Before I get into the details of how fetchPage() and fetchUrls() work, let's first answer your question of how to wait before fetching the next page. Non-integer delays are truncated to an integer. When delay is larger than 2147483647 or less than 1, the delay will be set to 1. The callback will be called as close as possible to the time specified. For instance, this would be your main function: const urls = await fetchUrls(INITIAL_URL) Node.js makes no guarantees about the exact timing of when callbacks will fire, nor of their ordering. number of milliseconds, blocking the main thread. I am a big fan of the async library and I've used for a long time. Consider the work () function defined below: // A function that will sleep synchronously for a certain. Delaying multiple page fetches with async/await
