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

Make it clearer that .share() can only be called once on a promise

    • Type: Icon: Task Task
    • Resolution: Gone away
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Concurrency
    • Labels:
      None
    • Service Arch
    • Service Arch 2018-11-19, Service Arch 2018-12-03, Service Arch 2018-12-17, Service Arch 2018-12-31, Service Arch 2019-01-14, Service Arch 2019-01-28

      Right now it is easy enough to do something like

          auto pf = makePromiseFuture<int>();
          Future<void>::makeReady()
               .then([promise = pf.promise.share()]() mutable { promise.emplaceValue(1); })
               .onError([promise = pf.promise.share()](Status s) mutable { promise.emplaceValue(2); })
               .getAsync([](Status s) {});
      
           auto result = pf.future.get();
      

      without realizing that share() cannot be called twice on the same promise. This will hit this invariant, and it's not immediately clear what hitting that invariant means to someone not familiar with the futures code.

      It'd be better to require

      std::move(pf.promise).share()

      or

      SharedPromise<int> shared(std::move(promise));

      - something that indicates visually that the promise is invalid once share is called. At the very least adding an error message to the invariant would be helpful.

            Assignee:
            backlog-server-servicearch [DO NOT USE] Backlog - Service Architecture
            Reporter:
            matthew.saltz@mongodb.com Matthew Saltz (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: