mirror of
https://github.com/whyour/qinglong.git
synced 2025-06-06 01:07:36 +08:00
18 lines
365 B
TypeScript
18 lines
365 B
TypeScript
import pLimit from "p-limit";
|
|
import os from 'os';
|
|
|
|
const cpuLimit = pLimit(os.cpus().length);
|
|
const oneLimit = pLimit(1);
|
|
|
|
export function runWithCpuLimit<T>(fn: () => Promise<T>): Promise<T> {
|
|
return cpuLimit(() => {
|
|
return fn();
|
|
});
|
|
}
|
|
|
|
export function runOneByOne<T>(fn: () => Promise<T>): Promise<T> {
|
|
return oneLimit(() => {
|
|
return fn();
|
|
});
|
|
}
|