Uploaded image for project: 'Swift Driver'
  1. Swift Driver
  2. SWIFT-1612

Introduce a generic type for locked values

    XMLWordPrintable

Details

    • Improvement
    • Status: Backlog
    • Unknown
    • Resolution: Unresolved
    • None
    • None
    • None

    Description

      With the number of places in the code we now guard some value behind a lock and just have to remember that it should only be accessed via the lock, it would be a nice improvement to introduce some generic wrapper type like `Locked<T>` that stores a value of type `T` plus its corresponding `Lock` and has a method that lets you do something like

      myLockedThing.withLockedValue

      { value in // ... do something with value }

      The method would acquire the lock, execute your provided closure with the value it guards, then releases the lock. the locked value could be private to the `Locked` type so it's impossible to access it other than when you hold the lock, which would make it harder for us to forget to acquire the lock.

      Attachments

        Activity

          People

            Unassigned Unassigned
            kaitlin.mahar@mongodb.com Kaitlin Mahar
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: