File tree Expand file tree Collapse file tree 3 files changed +13
-4
lines changed
Expand file tree Collapse file tree 3 files changed +13
-4
lines changed Original file line number Diff line number Diff line change 11import { TimeoutError } from './TimeoutError' ;
22
3+ interface DeferredOptions {
4+ errorMessage ?: string ;
5+ }
36/**
47 * Deferred Implementation
58 *
@@ -10,8 +13,10 @@ export class Deferred<T> {
1013 protected _resolve : ( value : T ) => void ;
1114 protected _reject : ( error : Error ) => void ;
1215 protected _timeout : NodeJS . Timer ;
16+ private options : DeferredOptions ;
1317
14- constructor ( ) {
18+ constructor ( options : DeferredOptions = { } ) {
19+ this . options = options ;
1520 this . _promise = new Promise ( ( resolve , reject ) => {
1621 this . _reject = reject ;
1722 this . _resolve = resolve ;
@@ -23,7 +28,9 @@ export class Deferred<T> {
2328
2429 this . _timeout = setTimeout ( ( ) => {
2530 callback ( ) ;
26- this . reject ( new TimeoutError ( 'Operation timeout' ) ) ;
31+ this . reject (
32+ new TimeoutError ( this . options . errorMessage ?? 'Operation timeout' ) ,
33+ ) ;
2734 } , timeoutInMillis ) ;
2835 }
2936
Original file line number Diff line number Diff line change @@ -433,7 +433,9 @@ export class Pool<RawResource> {
433433 ) ;
434434 }
435435
436- const deferred = new Deferred < RawResource > ( ) ;
436+ const deferred = new Deferred < RawResource > ( {
437+ errorMessage : 'Pool acquire operation timeout' ,
438+ } ) ;
437439 deferred . registerTimeout ( this . acquireTimeoutMillis , ( ) => {
438440 // timeout triggered, promise will be rejected
439441 // remove this object from pending list
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ tap.test('pool expands only to max limit', (t) => {
2323 . then ( ( obj ) => {
2424 return pool . acquire ( ) . catch ( ( e ) => {
2525 t . ok ( e instanceof TimeoutError ) ;
26- t . ok ( e . message === 'Operation timeout' ) ;
26+ t . ok ( e . message === 'Pool acquire operation timeout' ) ;
2727 pool . release ( obj ) ;
2828 t . end ( ) ;
2929 } ) ;
You can’t perform that action at this time.
0 commit comments