-
Type: Task
-
Resolution: Gone away
-
Priority: 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.