A discrete-event simulation library for Deno. Features a stateful, event-driven process-as-state-machine model with UNIX-like fork/exec semantics, explicit process continuations, and inter-process synchronization.
- ⚙️ Define processes using finite-state machines -- your code determines state transitions;
- 🔗 Use resources to model shared data -- synchronize processes using
put/getsemantics; - ⏯️ Leverage immutability to pause and resume simulations -- snapshot the whole simulation state and restore it later.
Planned features:
- 🔌 Socket-based communication -- easily build user interfaces;
- 🌐 Run distributed simulations -- deploy processes on different machines.
Process representation
- Each process is a finite state machine:
ProcessDefinitiondrives transitions; runtime snapshot isProcessStatecontaining process step and data; - Steps are explicit
ProcessStepvalues; user defines how their process transitions from one state to another.
Scheduling and execution semantics
- Processes execute only when an associated
Eventis dequeued. Events are ordered by scheduled time then priority; - Simulation advances time with each event, executes their process, updates the process state, and schedules any new events returned.
Lifecycle and persistence
- Process instances are stored in a global simulation state;
- An event is never reprocessed and is marked
Finishedas it has been handled.
Concurrency and composition model
- Child processes are spawned by emitting new events; parent–child relationships are tracked via parent on events;
- Three spawn styles supported:
fork-like continuation (child keeps parent process type and current progress/state);exec-like inheritance (child inherits parent data but starts at the process initial step) andexecve-like spawn (clean state from process definition and explicitly provided input data); - Blocking is modeled by a
Waitingevent state and by resumption through newly emitted continuation events when conditions are satisfied.
Continuations and temporal patterns
- Process logic is continuation-driven: each step returns the next event(s) that carry execution forward;
- A process step does not "loop": state-machine progress happens only through emitted next event(s), including revisiting the same step in a later transition;
- "Sleeping" is modeled by returning a continuation scheduled in the future.
Messaging and data flow
- Data flows via process data and step inheritance flags;
- Events contain a
ProcessCallthat can carry initialization data for process state; child processes can merge inherited state; - This lets workflows evolve over multiple events (e.g., arrive -> wait -> handle -> done) while carrying context forward.
Install Deno; see the guide.
Run the examples:
deno task example_scheduling
deno task example_synchronization
deno task example_stack_sizeRun tests:
deno task test