Skip to content

AfterRelease hook does not provide context access #1666

Answered by jackc
gcfabri asked this question in Q&A
Discussion options

You must be logged in to vote

AfterRelease doesn't take a context because it is called asynchronously after Release which is itself cannot block. i.e. It's not clear what cancelling a Release would even mean. I hadn't considered needing to pass arbitrary extra data.

I'm not sure of a good way to do this... but I can think of a way...

You could have a global map[*pgx.Conn]context.Context. You would need to guard access with a mutex, but you could set the value in BeforeAcquire and retrieve and delete it in AfterRelease.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by gcfabri
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants