@lumera/sdk-js
    Preparing search index...

    Class TaskManager

    TaskManager monitors the status of a Cascade task using a polling strategy.

    This class provides a polling-based mechanism to track task completion, serving as a fallback to the preferred SSE (Server-Sent Events) method. It periodically queries the task status endpoint until the task reaches a terminal state (completed or failed).

    const taskManager = new TaskManager(snapiClient, 'task-123');

    try {
    const task = await taskManager.waitForCompletion();
    console.log('Task completed:', task);
    } catch (error) {
    console.error('Task failed:', error);
    }
    Index

    Constructors

    Methods

    • Wait for the task to complete by polling its status

      This method periodically checks the task status until it reaches a terminal state (completed or failed). It will continue polling at the configured interval until either:

      • The task completes successfully (resolves with task details)
      • The task fails (rejects with error)
      • The timeout is reached (rejects with timeout error)

      Returns Promise<{ progress?: number; status?: string; taskId?: string }>

      Promise resolving to the completed task details

      If the task fails or times out

      const taskManager = new TaskManager(client, 'task-123', {
      pollInterval: 1000, // Poll every second
      timeout: 60000 // 1 minute timeout
      });

      try {
      const task = await taskManager.waitForCompletion();
      console.log('Task completed successfully');
      } catch (error) {
      console.error('Task did not complete:', error.message);
      }
    • Wait for download task completion using Server-Sent Events (SSE)

      This method provides real-time monitoring of download task status via SSE, which is more efficient than polling. It listens for the sdk:completed event to detect task completion, and handles error events appropriately.

      Returns Promise<void>

      Promise resolving when the task completes successfully

      If the task fails or the connection closes unexpectedly

      const taskManager = new TaskManager(client, 'task-123');

      try {
      await taskManager.waitForDownloadCompletion();
      console.log('Download task completed successfully');
      } catch (error) {
      console.error('Download task failed:', error.message);
      }