Loop Engine

Running Loops

createLoopSystem

createLoopSystem(options)

Factory from @loop-engine/sdk:

1createLoopSystem(options: {
2 loops: LoopDefinition[]
3 store?: LoopStore
4 guards?: GuardRegistry
5 signals?: boolean
6}): {
7 engine: LoopEngine
8 eventBus: InMemoryEventBus
9 signals?: SignalEngine
10}
  • loops is required and becomes the in-memory registry.
  • store defaults to memoryStore().
  • guards defaults to defaultRegistry from @loop-engine/guards.
  • signals: true adds a default SignalEngine.

Pattern 1: zero-config

1import { createLoopSystem } from '@loop-engine/sdk'
2 
3const { engine, eventBus } = createLoopSystem({ loops: [definition] })

Pattern 2: custom store (PostgreSQL adapter)

1import { createLoopSystem } from '@loop-engine/sdk'
2import { postgresStore } from '@loop-engine/adapter-postgres'
3import { Pool } from 'pg'
4 
5const pool = new Pool({ connectionString: process.env.DATABASE_URL })
6const { engine } = createLoopSystem({
7 loops: [definition],
8 store: postgresStore(pool)
9})

Pattern 3: signals enabled

1import { createLoopSystem } from '@loop-engine/sdk'
2 
3const { signals } = createLoopSystem({
4 loops: [definition],
5 signals: true
6})
7 
8signals?.subscribe((signal) => {
9 console.log(signal.type, signal.subject)
10})