qinglong/back/shared/pLimit.ts
2023-05-30 17:31:31 +08:00

10 lines
223 B
TypeScript

import pLimit from "p-limit";
import os from 'os';
const cronLimit = pLimit(os.cpus.length || 3);
export function runCronWithLimit<T>(fn: () => Promise<T>): Promise<T> {
return cronLimit(() => {
return fn();
});
}