| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Control your function easily.
npm install controlaimport { controlAsyncFunction } from 'controla'
const outerAbortController = new AbortController()
const { run, abort } = controlAsyncFunction(
async ({ signal }) => {
return 'Hello, world!'
},
{
signal: outerAbortController.signal, // Optional, AbortSignal
timeout, // Optional, ms
}
)Deduplicate concurrent async calls into a single shared "flight", with optional idle cache window and per-call controls.
import { controlSingleFlight } from 'controla'
// Your flight function (single-flight deduped); use AbortSignal to support cancellation
const fetchUser = async ({ signal }: { signal?: AbortSignal }) => {
const res = await fetch('/api/user', { signal })
if (!res.ok) throw new Error('request failed')
return (await res.json()) as { id: string; name: string }
}
// Minimal usage
const { run, abortAll } = controlSingleFlight(fetchUser, { timeout: 10_000, idleReleaseTime: 1000 })
const u1 = await run().promise // shared flight for concurrent callers
const u2 = await run().promise // reused within idle window
await run({ refresh: true }).promise // force a new flight
await run({ timeout: 500 }).promise // per-call timeout
abortAll() // abort underlying flight for everyoneKey points:
| Back | FazBrowse Home | New Git URL |