WithPermit
withPermit
Convenience function to execute a function with a permit using the default semaphore.
Example
const controller = new AbortController();
const result = await withPermit('database-connection', async () => {
// This code runs with a permit from the semaphore
return await executeDatabaseQuery();
}, 30000, controller.signal);
controller.abort(); // Cancels the permit acquisition
Signature
function withPermit<T>(key: string, fn: () => Promise<T> | T, timeout?: number, signal?: AbortSignal): Promise<T>
Parameters
key
parameter
string
fn
parameter
() => Promise<T> | T
timeout
parameter
number
signal
parameter
AbortSignal