Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-54356

make a ReturnableScopeGuard type

    • Service Arch

      It seems like it would be nice to be able to return a ScopeGuard-like type from a function. Eg, construct a guard at the top of a pushState() function to restore it to the then-current state prior to modifying, then return it so that the caller of pushState() will always automatically pop its state modification.

       

      Based on a slack discussion, we decided it would be best to be a separate type to avoid breaking the rule that it is always safe (and preferred!) to use [&] captures with makeGuard (unless you are literally typing return makeGuard([&]{...}) but then you know what you are doing and deserve to win stupid prizes). From the same discussion, it would be safer if the type only supported move construction but not move assignment. This allows the important use case of returning a guard, but disallows silly operations like swapping two guards.

            Assignee:
            backlog-server-servicearch [DO NOT USE] Backlog - Service Architecture
            Reporter:
            mathias@mongodb.com Mathias Stearn
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: