API reference

One class. Four actions. Five state values.

The surface is intentionally compact. State stays inspectable, and execution advances only through an explicit hand-off.

Methods

new Stack()

Creates an isolated empty stack with auto-run enabled and stop disabled.

Returns
A new Stack instance.

stack.add(...tasks)

Validates the complete batch, appends it, and starts the newest task when the stack is idle, unblocked, and in auto-run mode.

Returns
The stack instance for chaining.
Throws
TypeError when any item is not a function. Nothing is added on failure.

stack.next()

Selects and invokes one newest pending task with the stack bound as this. Empty or stopped stacks become idle.

Returns
undefined; callback return values are ignored.
Throws
The callback's original error, after restoring the idle state.

stack.clear()

Replaces the pending callback array without interrupting a callback that is already active.

Returns
The new empty live array.

stack.contents([tasks])

Reads the live callback array. When an argument is provided, validates and installs that array by reference.

Returns
The current live callback array.
Throws
TypeError unless the replacement is an array containing only functions.

State

MemberTypeDefaultBehavior
stack.stackArray[]Live pending-task array, bottom first and newest last. Read/write with validation on replacement.
stack.sizenumber0Read-only current pending-task count.
stack.runningbooleanfalseRead-only execution state. It remains true while an active task has not handed off.
stack.autoRunany truthy/falsytrueWhen truthy, an idle eligible stack starts as soon as work is added.
stack.stopany truthy/falsyfalseWhen truthy, next() consumes nothing and sets running false.
The array is deliberately live.

Advanced schedulers may inspect or reorder pending tasks directly. Prefer add() and whole-array replacement when you want validation before mutation.

Export shapes

import Stack, { Stack as NamedStack } from 'easy-stack';
console.log(Stack === NamedStack); // true

const RequiredStack = require('easy-stack');
console.log(RequiredStack === RequiredStack.Stack); // true
Next pageExecution patterns