Skip to content

SDK Modules (/packages/sdk): Add support for the Abort Controller API #567

@7hacker

Description

@7hacker

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);
   }
 }
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions