Skip to content

useLockFn

Category
Export Size
156 B
Last Changed
5 days ago

Add a lock to an async function so overlapping calls are dropped.

Demo

Usage

tsx
import { 
useLockFn
} from '@reause/shared'
const
submit
=
useLockFn
(async (
id
: string) => {
await api.submit(
id
)
})
submit
('a') // runs
submit
('b') // dropped — resolves to `undefined`, does not reject

Type Declarations

ts
export function useLockFn<P extends any[] = any[], V = any>(fn: (...args: P) => Promise<V>)

Source

Source · Demo

Contributors

hairyf

Changelog

v0.1.7 on
a286d - feat(shared): add useLockFn (#945)

Released under the MIT License. v0.1.8