Make semantically-const methods in SharedPromise const
Summary: 1) SharedPromise is semantically a regular Promise one can get multiple Futures off. One would expect that all methods which are const in Promise to also be const in SharedPromise - but they are not because their implementations needs using a mutex. 2) Semantically, `SharedPromise::getFuture()` and `SharedPromise::getSemiFuture()` do not change the observable state of the object. 3) As real-life consequence, these non-const `SharedPromise` methods become viral in downstream code which then has to hack around it in downstream `const` methods by marking the SharedPromise instance mutable. That solution leads to the program being less const-correct than it should be, as now the type system allows `const` methods to reassign or `setValue` the SharedPromise. This diff changes `hasResult`, `isFulfilled`, `size()`, `getFuture()` and `getSemiFuture()` to be `const`. In order to achieve that, the private fields `mutex_` and `size_` had to be marked `mutable`. (Note: this ignores all push blocking failures!) Reviewed By: yfeldblum Differential Revision: D18565877 fbshipit-source-id: ff63a48c02235f72c5b0191423ae68f7b7c42fb3
Showing
Please register or sign in to comment