A super-light asynchronous task orchestrator that distributes queued requests across a pool of async functions ("threads"), preserving FIFO order — ideal for real-time apps, agents, or any async-heavy workload.
MTFIFO is a zero-dependency FIFO-first async job manager. It lets you:
- Schedule many concurrent task requests
- Distribute them over custom thread functions
- Maintain FIFO discipline
- Get notified on success, failure, or all-done
It’s designed for developers building custom task pipelines, async microservices, or AI agents — where every millisecond and execution order matters.
Modern async systems are:
- ⚡ High-throughput (massive request volume)
- 🔄 Unpredictable (varying task times, streaming, retries)
- 🧬 Fine-grained (micro-inference, micro-decisions)
- 🎯 Deterministic-demanding (AI agents, reproducibility, latency guarantees)
But most orchestration tools are:
- 🏋️♂️ Too bloated (framework-heavy, dependency-locked)
- 🪵 Too rigid (static pipelines, no reactive control)
- 🛑 Not low-level enough (can’t “touch the metal”)
MTFIFO-JS solves this with:
- ✔️ Minimalism — Zero-dependency, browser/server-ready
- ✔️ Determinism — Explicit queueing, FIFO handling, and state clarity
- ✔️ Performance — Threaded execution, micro-latency tuning
- ✔️ Control — You define the logic, timing, and routing
Built for builders. Meant for systems where you want precision, not just “it works.”
- FIFO queue management
- Native
setInterval-based polling - Event hooks for
"SUCCESS","ERROR","END" - Dynamic thread pool resizing
- Lightweight: <150 lines, no dependencies
Start the pool with custom thread handlers (async functions).
const pool = new MTFIFO({ THREADS: [async (req) => req.func(req.params)] });Listen for task results or lifecycle events:
pool.on("SUCCESS", (res) => console.log("✔️", res));
pool.on("ERROR", (e) => console.warn("❌", e));
pool.on("END", () => console.log("🏁 All done"));Add one or more tasks to the pool.
pool.add_requests([
{ params: { input: "someData" }, func: myAsyncFunc }
]);Inject more thread handlers at runtime:
pool.add_threads([
async (request) => request.func(request.params)
]);Control polling manually if needed (starts automatically on .add_requests()).
const THREADS = Array.from({ length: 3 }, () => async (req) => req.func(req.params));
const pool = new MTFIFO({ THREADS });
const REQUESTS = Array.from({ length: 10 }, (_, i) => ({
params: { id: i },
func: async ({ id }) => {
console.log(`START ${id}`);
await new Promise(res => setTimeout(res, Math.random() * 2000));
console.log(`END ${id}`);
return `Result ${id}`;
}
}));
pool.on("SUCCESS", (res) => console.log("✔️", res));
pool.on("ERROR", (e) => console.warn("❌", e));
pool.on("END", () => console.log("✅ All done"));
pool.add_requests(REQUESTS);- Custom agent pipelines
- Async-heavy APIs
- Web scraping engines
- Multi-user LLM backends
- Anywhere async order matters
git clone https://github.com/Muad-Bohmosh/mtfifo-js
cd mtfifo-js
node index.jsOr install globally:
npm install mtfifo-js📣 Use It as you please under LICENSE terms
Like everything else, I Built it Because I Needed it.
see the LICENSE file for details.
Contributions welcome. — thanks in advance!