Skip to content

Commit

Permalink
feat: add TimeoutError
Browse files Browse the repository at this point in the history
  • Loading branch information
alexghr committed Apr 15, 2024
1 parent 20d290c commit 0865b4d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@
* can be used to handle cases where a process or task is terminated before completion.
*/
export class InterruptError extends Error {}

/**
* An error thrown when an action times out.
*/
export class TimeoutError extends Error {}
3 changes: 2 additions & 1 deletion yarn-project/foundation/src/fifo/memory_fifo.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { TimeoutError } from '../error/index.js';
import { createDebugLogger } from '../log/index.js';

/**
Expand Down Expand Up @@ -46,7 +47,7 @@ export class MemoryFifo<T> {
const index = this.waiting.findIndex(r => r === resolve);
if (index > -1) {
this.waiting.splice(index, 1);
const err = new Error('Timeout getting item from queue.');
const err = new TimeoutError('Timeout getting item from queue.');
reject(err);
}
}, timeout * 1000);
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/foundation/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export * as bigintBuffer from './bigint-buffer/index.js';
export * as collection from './collection/index.js';
export * as committable from './committable/index.js';
export * as crypto from './crypto/index.js';
export * as errors from './errors/index.js';
export * as errors from './error/index.js';
export * as ethAddress from './eth-address/index.js';
export * as fields from './fields/index.js';
export * as fifo from './fifo/index.js';
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/foundation/src/sleep/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { InterruptError } from '../errors/index.js';
import { InterruptError } from '../error/index.js';

/**
* InterruptibleSleep is a utility class that allows you to create an interruptible sleep function.
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/foundation/src/sleep/sleep.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { jest } from '@jest/globals';

import { InterruptError } from '../errors/index.js';
import { InterruptError } from '../error/index.js';
import { InterruptibleSleep } from './index.js';

describe('InterruptibleSleep', () => {
Expand Down

0 comments on commit 0865b4d

Please sign in to comment.