![]() ![]() 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. For instance, this would be your main function: const urls = await fetchUrls(INITIAL_URL) I am a big fan of the async library and I've used for a long time. In the example below, the greeting function accepts two argumnets, phrase and name. You can also pass further optinal parameters to setTimeout (). Once that one second has passed, the code in setTimeout () runs. Delaying multiple page fetches with async/await Instead, that line is skipped for the time being, and the line console.log ('Good Afternoon') is executed. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |