1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/common/utils/with-concurrency-limit.ts
Sebastian Malton 1841907eb8 More improvements to requestApiResources
- Also move files to better places

Signed-off-by: Sebastian Malton <sebastian@malton.name>
2022-12-21 08:32:13 -05:00

14 lines
468 B
TypeScript

/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import plimit from "p-limit";
export type ConcurrencyLimiter = <Args extends any[], Res>(fn: (...args: Args) => Res) => (...args: Args) => Promise<Res>;
export function withConcurrencyLimit(limit: number): ConcurrencyLimiter {
const limiter = plimit(limit);
return fn => (...args) => limiter(() => fn(...args));
}