Skip to content

Muad-Bohmosh/mtfifo-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧠 MTFIFO: A Minimalist Multi-Threaded FIFO Orchestrator for AI (javascript)

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.

πŸš€ Ultra-Light. Dynamic. Runs Anywhere.


🧩 What is MTFIFO?

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.


🧠 Why It 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.”


βœ… Features

  • FIFO queue management
  • Native setInterval-based polling
  • Event hooks for "SUCCESS", "ERROR", "END"
  • Dynamic thread pool resizing
  • Lightweight: <150 lines, no dependencies

🧩 Core API

new MTFIFO({ THREADS })

Start the pool with custom thread handlers (async functions).

const pool = new MTFIFO({ THREADS: [async (req) => req.func(req.params)] });

.on(event, callback)

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_requests(requests)

Add one or more tasks to the pool.

pool.add_requests([
  { params: { input: "someData" }, func: myAsyncFunc }
]);

.add_threads(threads)

Inject more thread handlers at runtime:

pool.add_threads([
  async (request) => request.func(request.params)
]);

.Start() and .Stop()

Control polling manually if needed (starts automatically on .add_requests()).


πŸ§ͺ Quick Example

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);

🧠 Ideal For:

  • Custom agent pipelines
  • Async-heavy APIs
  • Web scraping engines
  • Multi-user LLM backends
  • Anywhere async order matters

πŸ›  Install & Use

git clone https://github.com/Muad-Bohmosh/mtfifo-js
cd mtfifo-js
node index.js

Or install globally:

npm install mtfifo-js

πŸ“£ Use It as you please under LICENSE terms

Like everything else, I Built it Because I Needed it.


πŸ“„ License

see the LICENSE file for details.


Contributions welcome. β€” thanks in advance!

About

🧠 MTFIFO: A Minimalist Multi-Threaded FIFO Orchestrator for AI (javascript)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors