@livekit/agents 1.0.20 → 1.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/utils.ts CHANGED
@@ -385,8 +385,6 @@ export class AudioEnergyFilter {
385
385
  }
386
386
  }
387
387
 
388
- export const TASK_TIMEOUT_ERROR = new Error('Task cancellation timed out');
389
-
390
388
  export enum TaskResult {
391
389
  Timeout = 'timeout',
392
390
  Completed = 'completed',
@@ -481,34 +479,30 @@ export class Task<T> {
481
479
  async cancelAndWait(timeout?: number) {
482
480
  this.cancel();
483
481
 
484
- try {
485
- // Race between task completion and timeout
486
- const promises = [
487
- this.result
488
- .then(() => TaskResult.Completed)
489
- .catch((error) => {
490
- if (error.name === 'AbortError') {
491
- return TaskResult.Aborted;
492
- }
493
- throw error;
494
- }),
495
- ];
496
-
497
- if (timeout) {
498
- promises.push(delay(timeout).then(() => TaskResult.Timeout));
499
- }
500
-
501
- const result = await Promise.race(promises);
482
+ // Race between task completion and timeout
483
+ const promises = [
484
+ this.result
485
+ .then(() => TaskResult.Completed)
486
+ .catch((error) => {
487
+ if (error.name === 'AbortError') {
488
+ return TaskResult.Aborted;
489
+ }
490
+ throw error;
491
+ }),
492
+ ];
493
+
494
+ if (timeout) {
495
+ promises.push(delay(timeout).then(() => TaskResult.Timeout));
496
+ }
502
497
 
503
- // Check what happened
504
- if (result === TaskResult.Timeout) {
505
- throw TASK_TIMEOUT_ERROR;
506
- }
498
+ const result = await Promise.race(promises);
507
499
 
508
- return result;
509
- } catch (error) {
510
- throw error;
500
+ // Check what happened
501
+ if (result === TaskResult.Timeout) {
502
+ throw new Error('Task cancellation timed out');
511
503
  }
504
+
505
+ return result;
512
506
  }
513
507
 
514
508
  /**