Wednesday 28 August 2019

Pausing between API calls—sync or async?

Hey all, I'm currently working on a web app that involves lots of sequential calls to an external API. This particular API provides a list of data but it has a limit on the number of items that are given per request. For this reason, I have to loop through all the pages of the data to get everything I need. I wish to space out these requests by a second or so to minimize the traffic of the API.​So far with node.js, all the external API calls that I've made have been asynchronous (using promises) because it didn't matter how long it takes to move onto the next step, but I don't think that would be the best approach for this situation. Based on this assumption, how can I accomplish this in a synchronous manner? If it makes a difference, these requests are being handled by a third-party NPM package that uses callback functions. I know that it's not a good idea to force pauses into what would be asynchronous code, but I'm not sure how to translate it to the functionality I need.​Thank you so much for your input!

Submitted August 29, 2019 at 03:56AM by MindBodyLightSound

No comments:

Post a Comment