@comake/skl-js-engine
Version:
Standard Knowledge Language Javascript Engine
68 lines • 2.51 kB
TypeScript
import type { TransportConfig } from './transport';
import type { ExecutionOptions, IShutdownOptions } from './types';
export declare type IJSCallbacks = Record<string, (...args: any[]) => any>;
/**
* JSExecutor V2 with enhanced abort control for immediate shutdown
*
* @example Writing abort-aware callbacks:
* ```typescript
* const jsExecutor = new JSExecutorV2(scriptPath, {
* async myCallback(): Promise<string> {
* return new Promise((resolve, reject) => {
* const timeoutId = setTimeout(() => resolve('done'), 5000);
*
* // Listen to the global abort signal to clean up resources
* const abortSignal = JSExecutorV2.getGlobalAbortSignal();
* const onAbort = () => {
* clearTimeout(timeoutId);
* reject(new Error('Operation aborted'));
* };
*
* if (abortSignal.aborted) {
* onAbort();
* return;
* }
*
* abortSignal.addEventListener('abort', onAbort);
* });
* }
* });
* ```
*/
export declare class JSExecutor {
private readonly executorScriptPath;
private readonly callbacks;
private isInitialized;
private server?;
private transport?;
private readonly abortController;
private static readonly globalAbortController;
private shutdownTimeout?;
constructor(executorScriptPath: string, callbacks: Record<string, (...args: any[]) => any>);
/**
* Static method to check if any JSExecutor instance is being shut down
* Callbacks can use this to check if they should abort their operations
*/
static isShuttingDown(): boolean;
/**
* Get the global abort signal that callbacks can listen to
* This allows callbacks to immediately abort when any JSExecutor shuts down
*/
static getGlobalAbortSignal(): AbortSignal;
initialize(config?: TransportConfig, executionOptions?: ExecutionOptions): Promise<void>;
shutdown(options?: IShutdownOptions): Promise<void>;
private shutdownCore;
private rpcComplaintCallback;
/**
* Wrap a callback with abort functionality
* The callback will be automatically aborted if JSExecutor is shut down
*/
private wrapCallbackWithAbort;
execute(code: string, args: Record<string, any>, executionOptions: ExecutionOptions): Promise<any>;
/**
* Legacy method for backward compatibility
* @deprecated Use execute() instead
*/
call(methodName: string, ...args: any[]): Promise<any>;
}
//# sourceMappingURL=jsExecutor.d.ts.map