Add onidle callback option #1147
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #1100
Saw this issue and it would help us out with our own app on Vercel.
Adds an
onidlecallback option that fires when a connection returns to the pool after completing queries.Went with the callback pattern (
onidle) instead of emitting an event to stay consistent withonclose,onnotify, etc.Fires in the
move()function when a connection transitions to the open queue - this is the same placeidleTimer.start()is called, so it felt like the natural spot for "connection is now idle."Usage
Or set after creation (e.g., like Vercel's
attachDatabasePool()):