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.
AK
Alex / KATT 🐱179d ago
You could probably do a custom link But if you have multiple users it won't really matter
AK
Alex / KATT 🐱179d ago
Links Overview | tRPC
Links enable you to customize the flow of data between the tRPC Client and Server. A link should do only one thing, which can be either a self-contained modification to a tRPC operation (query, mutation, or subscription) or a side-effect based on the operation (such as logging).
N
Nick179d ago
This does sound like more of a backend concern, some async worker process and a status in redis for whether the data is ready. Could be polled and awaited that way
More Posts
Global metadata / filters: Re-validate all queriesHi all, Simple question, I'm looking for the most efficient way to add some global state to all queAttempted import error: 'hashQueryKey' is not exported from '@tanstack/react-query' issuei'm getting this error while trying trpc with latest next version , i tried downgrading but got anotTRPC cant handle ErrorHi, can someone please help me: https://stackoverflow.com/questions/77333318/trpc-handle-trpcerrorI want to create a wrapper for TRPC.init but I can't seem to get the context type correct.I want to get wrap trpc.initTrouble getting a TRPC client in Astro SSR pages, instead I get a noopI'd like to add TRPC to an Astro site. I have an SSR route here (https://github.com/aisflat439/anothWhy webhooks does not work with TRPC?I have a what suppose to be a webhook: ``` deposit: publicProcedure.input(z.any()).mutation(asynctRPC set up errorHey guys, I've been trying to set up tRPC, but unfortunatyy getting this error and it is really unclVercel maxDuration with tRPCHow do you extend extend tRPC timeouts on Vercel? I tried this in `vercel.json`: ```json { "functWhere is client side error handling documented?In the docs, I can only find error handling for the backend. But I want to get the TRPCError code indoes api.myQuery.invalidate() works if the query is not made at the first place?from testing, the invalidate runs the query, but it shouldn't because there is no cache? how do i iworking with custom errors and trpc errorFormatterHey guys. I'm trying to refactor my app so that all errors extend a BaseError class to make dealing tRPC and OpenTelemetryDoes anyone have experience with instrumenting tRPC with OTEL for tracing? It would be pretty neat