kjetil.hartveit
How to add a short delay between requests
Environment: nextjs 13, node 18, npm, trpc 10.9.0
I'm wondering if it's possible to add a short delay between requests when either using httpBatchLink or httpLink.
Background: I'm in a bit of a volatile situation as a 3rd-party API of my app doesn't support any more than 10 requests per minute. On a particular page there are sent several http requests of which multiple calls the 3rd-party API. I have implemented Upstash/redis caching for the requests, however whenever the cache have expired all requests are sent at the same time, thus no calls hits the cache as no requests has gone through and filled the cache yet.
I'm playing with an idea of detecting whether a request has started and then waiting on the request to finish to fill the cache. This must work across http requests so it's implemented using upstash/redis. However I may need a little delay between the requests to make it work somewhat.
Curious if anyone knows about other solutions should a delay not be feasible.
6 replies