You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I implemented a feature in my usage of this library to throw an error if the client hasn't been returned after a set amount of time, and automatically return the client to the pool:
asyncfunctionuse_client(fn){letclient=awaitpool.acquire()letpromises=[fn(client)]if(opts.borrowTimeoutMillis){promises.push(newPromise((_,reject)=>setTimeout(()=>reject('BORROW_TIMEOUT_REACHED'),opts.borrowTimeoutMillis)))try{returnawaitPromise.race(promises)}finally{.if(client){.pool.release(client)}}}use_client(client=>{./*your code using the client here */})
Edit: I modified the code to only throw the timeout if opts.borrowTimeoutMillis is set
Would be good to have this incorporated into the library somehow, I'm sure I'm not the first to implement something like this.
The text was updated successfully, but these errors were encountered:
I modified the function above to only throw the timeout, and only call setTimeout, if opts.borrowTimeoutMillis is set. More to the point though, the code snippet above was only representing how I was using the pool library in my code, and wasn't supposed to be generic to everyone's code. If incorporated into this library, I'd expect edits would need to be made to accommodate more use cases.
I implemented a feature in my usage of this library to throw an error if the client hasn't been returned after a set amount of time, and automatically return the client to the pool:
Edit: I modified the code to only throw the timeout if opts.borrowTimeoutMillis is set
Would be good to have this incorporated into the library somehow, I'm sure I'm not the first to implement something like this.
The text was updated successfully, but these errors were encountered: