async-minikit
v1.0.3
Published
A tiny zero-dependency async toolkit for Node.js and browsers. Includes sleep, sleepUntil, retry, timeout, debounceAsync, and throttleAsync.
Maintainers
Readme
✨ Features
sleep(ms)– delay executionsleepUntil(condition)– wait until a condition becomes trueretry(fn, options)– retry failed async operationstimeout(promise, ms)– enforce a timeout on a promisedebounceAsync(fn, ms)– debounce async functionsthrottleAsync(fn, ms)– throttle async functions- Zero dependencies
- Works everywhere (Node, Bun, Deno, Browser)
- Fully typed (TypeScript)
Perfect for backends, scripts, workers, SDKs, UI logic, and automation tools.
📦 Installation
npm install async-minikitOr:
yarn add async-minikit
pnpm add async-minikit
bun add async-minikit🚀 Quick Examples
1. Sleep
import { sleep } from 'async-minikit';
await sleep(500);
console.log('500ms passed');2. Sleep until condition
import { sleepUntil } from 'async-minikit';
let ready = false;
setTimeout(() => (ready = true), 1000);
await sleepUntil(() => ready, 100);
console.log('Ready!');3. Retry async logic
import { retry } from 'async-minikit';
const result = await retry(() => fetch('https://api.example.com/data'), { retries: 3, delay: 200 });4. Timeout a promise
import { timeout, sleep } from 'async-minikit';
await timeout(sleep(5000), 1000); // throws after 1s5. Debounce async function
import { debounceAsync } from 'async-minikit';
const save = debounceAsync(async () => {
console.log('Saving...');
}, 300);
save();
save();
save(); // Only one call executes6. Throttle async function
import { throttleAsync } from 'async-minikit';
const load = throttleAsync(async () => {
console.log('Loading...');
}, 1000);
setInterval(load, 200);📚 API Reference
sleep(ms: number): Promise<void>
Waits N milliseconds.
sleepUntil(condition, interval?)
Polls until condition becomes true.
await sleepUntil(() => userLoggedIn, 100);retry(fn, { retries, delay })
Retries an async function until it succeeds.
Defaults:
retries: 3;
delay: 100;timeout(promise, ms)
Rejects if the promise doesn’t resolve before ms.
debounceAsync(fn, ms)
Ensures the wrapped function only runs after no calls occur for ms.
throttleAsync(fn, ms)
Runs the function at most once per ms.
🛠️ TypeScript Support
Everything is strongly typed:
import type { AsyncFn } from 'async-minikit';Includes .d.ts type declarations with tsup.
🧪 Running Tests
npm testUses Vitest.
🔨 Build
npm run buildBuilds ESM + CJS outputs into /dist.
🤝 Contributing
PRs, issues, and ideas are welcome!
Star the repo ⭐ to support development.
📄 License
MIT © 2025
🚀 Spread the Word
If you like this library:
- ⭐ Star the GitHub repo
- Share it on Twitter/X
- Write a blog post
- Use it in your side projects
Thank you! 🙌
