GithubHelp home page GithubHelp logo

Comments (3)

abonander avatar abonander commented on August 17, 2024

If the key string you pass to PgAdvisoryLock is constant, you could put it in a smol::lock::OnceCell or a std::sync::LazyLock inside a static which would give you &'static references to it.

We could probably promote with_key() to a const fn so that it can be constructed directly in a static.

Otherwise, I'm not against .acquire_owned()/.try_acquire_owned() methods taking Arc<Self>. There's no real reason it doesn't exist already besides "I didn't think of it".

Couple bikeshedding things:

  • I'd prefer the _owned suffix to match Tokio: https://docs.rs/tokio/latest/tokio/sync/struct.RwLock.html#method.write_owned
  • It's a judgement call whether to take Arc<Self> or &Arc<Self>. The latter would increment the reference count lazily for less thrashing on highly contended locks, but the former would allow even the acquire() call itself to be moved into a task if desired.
    • I'm leaning toward Arc<Self> since it's strictly more flexible at the minor cost of requiring an explicit .clone(). Thrashing the refcount doesn't really matter since it's going to be dwarfed by the network overhead anyway. It also matches Tokio's API.

from sqlx.

bonsairobo avatar bonsairobo commented on August 17, 2024

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.

from sqlx.

abonander avatar abonander commented on August 17, 2024

Yeah, I'd appreciate it!

from sqlx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.