For long-running operations, the SDK could support the standard Abort Controller API to allow consumers to cancel operations:
async localizeText(
text: string,
params: Z.infer<typeof localizationParamsSchema>,
progressCallback?: (progress: number) => void,
abortSignal?: AbortSignal
): Promise<string> {
// Check if aborted
if (abortSignal?.aborted) {
throw new Error('Operation was aborted');
}
// Add abort signal event listener
const abortListener = () => {
// Handle abort
};
if (abortSignal) {
abortSignal.addEventListener('abort', abortListener);
}
try {
// Existing logic...
} finally {
// Clean up
if (abortSignal) {
abortSignal.removeEventListener('abort', abortListener);
}
}
}
For long-running operations, the SDK could support the standard Abort Controller API to allow consumers to cancel operations: