Stack vs queue

The order is the product decision.

A stack favors recency. A queue favors arrival order. Neither is universally better; each expresses a different promise to the work.

LIFO and FIFO compared

QuestionStack · LIFOQueue · FIFO
What runs next?The newest pending item.The oldest pending item.
What gets priority?Recent context and interruption.Arrival order and fairness.
Natural metaphorPapers placed on top of a desk pile.People joining the back of a line.
Good fitRefreshes, overrides, nested work, urgent state.Logs, jobs, transactions, ordered ingestion.
Starvation riskOlder work can wait while new work keeps arriving.Urgent new work waits behind the backlog.

Choose a stack when recency is meaningful

  • A fresh UI state makes an older render request less useful.
  • A task discovers nested prerequisite work that should happen immediately.
  • A reconnection or resource-open event should release the newest pending request first.
  • Users can supersede older intent with a newer action.

Choose a queue when every item deserves arrival-order processing or when older work must not be starved.

Reason from the visible array

easy-stack exposes pending tasks bottom first and newest last. That matches JavaScript's ordinary push() and pop() model:

stack.autoRun = false;
stack.add(first, second, newest);

console.log(stack.stack);
// [first, second, newest]

stack.next();
// newest executes
Protect old work when it matters.

If uninterrupted arrival order is a requirement, use a queue. Do not simulate FIFO by constantly reversing easy-stack's live array.

Next pageVersion benchmarks