You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Example use case: when a user selects a date, I load the shifts for that date. If the user swaps between several dates quickly, depending on my data fetching, if those request finish out of order my app might not use the shifts for the date the user currently has active.
A common browser-supported way to do this is through an AbortController.
In my exploring, SWR and other data fetching libraries recommend passing through an AbortController to fetch: vercel/swr#129
The OSDK wraps fetch, so I can't easily pass through an AbortController. You can provide your own fetch implementation when constructing a client, but that is not an ergonomic place to insert AbortController logic since it's usually dependent on state management you do not have access to when constructing the OSDK client.
Workaround
My current workaround is to use a a class I implemented called RequestCounter:
constcounter=newRequestCounter()asyncfunctionfetchShifts(){constcount=counter.increment('shifts')// Fetch objects async...constshifts=awaitclient(Shift).filter({ date }).fetchPage()if(count!==counter.get(APPOINTMENTS_KEY)){returnABORT_SYMBOL}// ... do something with shfits}
However this approach does not handle errors well and forces me to handle complexity that would be better abstracted away with an AbortController.
The text was updated successfully, but these errors were encountered:
Context
Example use case: when a user selects a date, I load the shifts for that date. If the user swaps between several dates quickly, depending on my data fetching, if those request finish out of order my app might not use the shifts for the date the user currently has active.
A common browser-supported way to do this is through an
AbortController
.In my exploring, SWR and other data fetching libraries recommend passing through an
AbortController
tofetch
: vercel/swr#129The OSDK wraps
fetch
, so I can't easily pass through anAbortController
. You can provide your ownfetch
implementation when constructing a client, but that is not an ergonomic place to insertAbortController
logic since it's usually dependent on state management you do not have access to when constructing the OSDK client.Workaround
My current workaround is to use a a class I implemented called
RequestCounter
:When I fetch data, I can say:
However this approach does not handle errors well and forces me to handle complexity that would be better abstracted away with an
AbortController
.The text was updated successfully, but these errors were encountered: