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!