Future handler for managing single long-running operations with simplified API.

Provides streamlined lifecycle management for models that typically handle one operation at a time. Automatically tracks progress and provides reactive status information for UI integration.

Example: Single Operation Management

@kosModel("brewing-system-model")
export class BrewingSystemModel implements FutureContainer {
futureHandler: FutureHandler;

constructor(modelId: string, options: any, context: KosCreationContext) {
this.id = modelId;
this.futureHandler = new FutureHandler(this);
}

async startBrewingCycle(recipe: Recipe): Promise<BrewingResult> {
const future = await this.createFuture('/brewing/start', { recipe });
this.futureHandler.addFuture(future);
return future;
}

get isOperationActive(): boolean {
return this.futureHandler.status !== 'NOT_RESOLVED';
}

get operationProgress(): number {
return this.futureHandler.progress;
}

onFutureUpdate(future: IFutureModel): void {
// Handle progress updates from the active Future
console.log(`Brewing: ${future.progress}% complete`);
}
}

Type Parameters

  • T extends object = Record<string, unknown>

Implements