Skip to content

Commit

Permalink
Better Pool.ready()
Browse files Browse the repository at this point in the history
We need to unref setTimeout so it doesn't block the app from closing

Simplified version of a68426e
  • Loading branch information
joshbetz committed Nov 22, 2022
1 parent c91eb61 commit 68a8e33
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,17 @@ export default class Pool extends EventEmitter {
}

async ready() {
return this.pool.ready();
return new Promise( ( resolve ) => {
const isReady = () => {
if ( this.pool.available >= this.pool.min ) {
resolve( true );
} else {
setTimeout( isReady, 100 ).unref();
}
};

isReady();
} );
}

async use( fn: ( client: Memcached ) => Promise<any> ): Promise<any> {
Expand Down

0 comments on commit 68a8e33

Please sign in to comment.