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

AsyncTry-until condition should have to take its input by const reference

    • Service Arch
    • Fully Compatible
    • Service Arch 2023-07-10, Service Arch 2023-07-24, Service Arch 2023-08-07

      I was helping diagnose a confusing situation yesterday where someone had something like this:

      AsyncTry([] { return SomeMoveOnlyType(); })
          .until([] (StatusWith<SomeMoveOnlyType> swType) { 
              return false; 
          })
          .on(executor, CancelationToken::uncancelable());
      

      It fails to compile because the lambda passed to 'until' is called with an lvalue, so it tries to copy the move-only type and fails to. Furthermore, it has to pass it as an lvalue because it still needs to use it later, so moving it into the condition isn't an option.

      These compiler errors are kind of cryptic. If we added a static assertion to ensure that the condition passed to 'until' had to take a const ref, then we could avoid this situation by emitting an easy to diagnose compiler error.

            Assignee:
            amirsaman.memaripour@mongodb.com Amirsaman Memaripour
            Reporter:
            matthew.saltz@mongodb.com Matthew Saltz (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: