-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AdvisoryLockGuard
without lifetime
#3429
Comments
If the key string you pass to We could probably promote Otherwise, I'm not against Couple bikeshedding things:
|
Unfortunately my keys are not constant. But I appreciate the idea. I agree with your design thoughts. I might have time to try implementing this feature if you're open to that. |
Yeah, I'd appreciate it! |
@abonander I'm starting to work on this, and I've had a few realizations. First, we probably don't need reference counting for this. I think I incorrectly pattern matched when proposing the But maybe there is some desire to use If we really did want to have a cloneable guard, I think it would also need a mutex around the connection, since most users would need a So for now I've opted to support pub struct PgAdvisoryLockGuardOwned<C: AsMut<PgConnection>> {
lock: Arc<PgAdvisoryLock>,
conn: Option<C>,
} I'm also wondering how we want to handle documentation. It seems like any new documentation would mostly duplicate existing documentation. Same with the tests. In fact, I wonder if we even want to keep the old Here's some progress in a draft PR: #3442 Any thoughts? |
AdvisoryLockGuard
AdvisoryLockGuard
without lifetime
Is your feature request related to a problem? Please describe.
I have an issue trying to use
AdvisoryLockGuard
. The lifetime prevents me from writing code that acquires the lock and then passes the guard into a'static
closure. This is relevant because I want to be able to write anaxum
request handler that upgrades to a websocket, but I want any errors that occur while acquiring the lock to be sent in aResponse
instead of a websocket close message.A rought sketch of how I want the code to look:
Describe the solution you'd like
I think having an API similar to this would work, though I'm not sure how feasible it would be to implement that for sqlx.
Describe alternatives you've considered
AFAICT my only (safe) option is to move the
PgAdvisoryLock
into the task scope that handles the socket. This means I must return any errors within that scope along the socket instead of in an HTTP response.The text was updated successfully, but these errors were encountered: