Overview
Therun() function is the entry point for starting your Runner application. It initializes a resource (and all its dependencies), manages the lifecycle, and returns a runtime instance for executing tasks and emitting events.
Signature
Parameters
The resource to run, optionally with configuration.Pass without config:Pass with config:
Configuration options for the runtime.
Returns
A runtime instance providing access to:
- Task execution via
runTask() - Event emission via
emitEvent() - Resource access via
getResourceValue()/getLazyResourceValue() - Root access via
getRootValue(),getRootConfig(),getRootId() - Lifecycle management via
dispose()
Examples
Basic Usage
With Configuration
With Options
Dry Run (Testing)
Custom Error Handling
Lifecycle
When you callrun(), the following happens:
- Registration Phase: All resources, tasks, events, hooks, and middleware are registered
- Validation Phase: Dependency graph and event emission graph are validated
- Override Processing: Any overrides are applied
- Listener Attachment: Event hooks are attached to their events
- Dependency Computation: Dependency injection is resolved
- Resource Initialization: Resources are initialized (sequentially or in parallel)
- Ready Event:
globals.events.readyis emitted - Runtime Active: The runtime is now ready to execute tasks and emit events
Error Handling
If initialization fails,run() will:
- Throw the error
- Automatically dispose all already-initialized resources
- Unhook process-level safety nets
Related
- Runtime API - Working with the runtime instance
- Resource Builder - Creating resources
- RunResult - Runtime instance methods