Function: createEngine() {#function-createengine}
createEngine(
opts?):Engine
Create a new engine instance with the given options.
The engine is a long-lived runtime designed to be embedded in your application process (e.g. alongside an HTTP server). It stays active as long as the host process runs, listening for events, dispatching handlers, and heartbeating leases. The dispatcher, heartbeat timer, and lease loop keep the Node.js event loop alive while there is active work.
For script-style usage where the process should exit after work completes, call Engine.drain to wait for all runs, then Engine.stop to tear down timers. Enabling the dev server also holds the process open until explicitly stopped.
Storage backend is selected based on the store option, the STATE_DB_PATH
environment variable, or defaults to in-memory.
Parameters {#parameters}
opts? {#opts}
EngineOptions = {}
Engine configuration options.
Returns {#returns}
A fully initialized Engine instance.
Example {#example}
import { createEngine } from '@yellatech/engine'
const engine = createEngine({ concurrency: 5 })
engine.register('greet', 'user.signup', async (ctx) => {
console.log(`Welcome, ${ctx.payload.name}!`)
return { success: true }
})
engine.emit('user.signup', { name: 'Alice' })
await engine.drain()
await engine.stop()