useLockFn
Add lock to an async function to prevent parallel executions.
Overview
Add lock to an async function to prevent parallel executions.
Installation
Open inpnpm dlx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useLockFn.jsonnpx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useLockFn.jsonyarn shadcn@latest add https://shadcn-ahooks.vercel.app/r/useLockFn.jsonbun shadcn@latest add https://shadcn-ahooks.vercel.app/r/useLockFn.jsonAdd lock to an async function to prevent parallel executions.
Examples
Basic usage
API
function useLockFn<P extends any[] = any[], V = any>(
fn: (...args: P) => Promise<V>
): fn: (...args: P) => Promise<V | undefined>;Result
| Property | Description | Type |
| -- | - |
| fn | The async function with lock | (...args: any[]) => Promise<any> |
Params
| Property | Description | Type | Default |
| -- | - | - |
| fn | An async function | (...args: any[]) => Promise<any> | - |