Download web/client/node_modules/axios/lib/helpers/throttle.js from amitesh11/pose: direct link, hf CLI and curl.
- Browser
- Download file 702 Bytes
-
https://huggingface.co/spaces/amitesh11/pose/resolve/main/web/client/node_modules/axios/lib/helpers/throttle.js
- Command line
-
hf download hf://spaces/amitesh11/pose/web/client/node_modules/axios/lib/helpers/throttle.js
-
curl -L -o throttle.js https://huggingface.co/spaces/amitesh11/pose/resolve/main/web/client/node_modules/axios/lib/helpers/throttle.js
702 Bytes
| ; | |
| /** | |
| * Throttle decorator | |
| * @param {Function} fn | |
| * @param {Number} freq | |
| * @return {Function} | |
| */ | |
| function throttle(fn, freq) { | |
| let timestamp = 0; | |
| const threshold = 1000 / freq; | |
| let timer = null; | |
| return function throttled(force, args) { | |
| const now = Date.now(); | |
| if (force || now - timestamp > threshold) { | |
| if (timer) { | |
| clearTimeout(timer); | |
| timer = null; | |
| } | |
| timestamp = now; | |
| return fn.apply(null, args); | |
| } | |
| if (!timer) { | |
| timer = setTimeout(() => { | |
| timer = null; | |
| timestamp = Date.now(); | |
| return fn.apply(null, args); | |
| }, threshold - (now - timestamp)); | |
| } | |
| }; | |
| } | |
| export default throttle; | |