AIDK API Reference / aidk-kernel / HandleFactory
Type Alias: HandleFactory()<THandle, TContext> ​
ts
type HandleFactory<THandle, TContext> = (events: EventEmitter, traceId: string, result: Promise<any>, context: TContext) => THandle;Defined in: packages/kernel/src/procedure.ts:168
Factory function for creating custom execution handles.
Use this to provide custom handle implementations with additional functionality like cancellation, status tracking, or specialized events.
Type Parameters ​
| Type Parameter | Default type | Description |
|---|---|---|
THandle extends ExecutionHandle<any> | ExecutionHandle<any> | The custom handle type (must extend ExecutionHandle) |
TContext extends KernelContext | KernelContext | The context type (must extend KernelContext) |
Parameters ​
| Parameter | Type |
|---|---|
events | EventEmitter |
traceId | string |
result | Promise<any> |
context | TContext |
Returns ​
THandle
Example ​
typescript
const customHandleFactory: HandleFactory = (events, traceId, result, context) => ({
events,
traceId,
result,
status: 'running' as const,
cancel() {
// Custom cancellation logic
},
getStatus() {
return this.status;
}
});
const proc = createProcedure(
{ handleFactory: customHandleFactory },
async (input) => input
);See ​
ExecutionHandle - The base handle interface