Skip to content

Commit

Permalink
add limiter
Browse files Browse the repository at this point in the history
  • Loading branch information
kilbot committed Jul 29, 2023
1 parent 291130f commit f66ab08
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wcpos/hooks",
"version": "1.3.4",
"version": "1.3.5",
"description": "Hooks for WooCommerce POS",
"author": "kilbot <[email protected]>",
"homepage": "https://github.com/wcpos/hooks#readme",
Expand All @@ -23,6 +23,7 @@
"@react-navigation/native": "6.1.7",
"@wcpos/components": "*",
"axios": "1.4.0",
"bottleneck": "^2.19.5",
"js-base64": "^3.7.5",
"lodash": "4.17.21",
"observable-hooks": "4.2.2",
Expand Down Expand Up @@ -56,7 +57,7 @@
"@wcpos/tsconfig": "*",
"babel-loader": "9.1.3",
"babel-plugin-react-native-web": "0.19.7",
"jest": "^29.6.1",
"jest": "^29.6.2",
"react-native-storybook-loader": "2.0.5",
"react-scripts": "5.0.1",
"react-test-renderer": "18.2.0",
Expand Down
5 changes: 4 additions & 1 deletion src/use-http-client/use-http-client.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';

import Bottleneck from 'bottleneck';
import merge from 'lodash/merge';
import set from 'lodash/set';

Expand All @@ -14,6 +15,8 @@ type AxiosError = import('axios').AxiosError;

export type RequestConfig = AxiosRequestConfig;

const limiter = new Bottleneck({ maxConcurrent: 10 });

/**
* Http Client provides a standard API for all platforms
* also wraps request to provide a common error handler
Expand Down Expand Up @@ -45,7 +48,7 @@ export const useHttpClient = (errorHandler?: (error: unknown) => unknown) => {
}

try {
const response = await http.request(config);
const response = await limiter.schedule(() => http.request(config));
return response;
} catch (error) {
log.error(error);
Expand Down

0 comments on commit f66ab08

Please sign in to comment.