[SERVER-38029] Make it clearer that .share() can only be called once on a promise Created: 08/Nov/18  Updated: 27/Oct/23  Resolved: 15/Jan/19

Status: Closed
Project: Core Server
Component/s: Concurrency
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Matthew Saltz (Inactive) Assignee: Backlog - Service Architecture
Resolution: Gone away Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Service Arch
Sprint: 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
Participants:

 Description   

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.



 Comments   
Comment by Matthew Saltz (Inactive) [ 15/Jan/19 ]

This function no longer exists

Generated at Thu Feb 08 04:47:45 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.