Skip to content

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 ParameterDefault typeDescription
THandle extends ExecutionHandle<any>ExecutionHandle<any>The custom handle type (must extend ExecutionHandle)
TContext extends KernelContextKernelContextThe context type (must extend KernelContext)

Parameters ​

ParameterType
eventsEventEmitter
traceIdstring
resultPromise<any>
contextTContext

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

Released under the MIT License.