SvelteStack / svelte-query

Performant and powerful remote data synchronization for Svelte
https://sveltequery.vercel.app
MIT License
822 stars 30 forks source link

asyncThrottle from createAsyncStoragePersistor-experimental is not throttling #77

Open a-jaouen opened 2 years ago

a-jaouen commented 2 years ago

The asyncThrottle function used by createAsyncStoragePersistor is not working as expected.

https://github.com/SvelteStack/svelte-query/blob/76d0591cbe6699329103db75f95427b48b507991/src/queryCore/createAsyncStoragePersistor-experimental/index.ts#L37

Behaviour: It will just delay the persistClient function with throttleTime but won't limit the number of concurrent call to 1.

Result: The data is not persisted correctly when multiple useQuery are used simultaneously.

Solution: I used the lodash throttle function instead and it is working like a charm. The persistence is working great as well.