(wangle) Future/Promise detachment
authorHans Fugal <fugalh@fb.com>
Mon, 30 Jun 2014 20:38:41 +0000 (13:38 -0700)
committerTudor Bosman <tudorb@fb.com>
Mon, 7 Jul 2014 15:42:20 +0000 (08:42 -0700)
commit03f412789821e5c1892dea9c887e0ecd63e1c705
tree19554678e685a3883a753198b86607281146f1fa
parent7609a2fb91619187ce9c609fb05f64bf6243f68a
(wangle) Future/Promise detachment

Summary:
Bring a bit more sanity to the lifetime. Now Future and Promise detach by calling the respective methods on State, and they do it during their destruction only. State manages its own lifetime.

Besides being cleaner, this also sets the stage for cancellation (where we'll need Future to hang on to its reference to State after setting the callback), and for folding in Later (we will have a bool for whether the future is hot and hold off executing the callback if it isn't).

Also cleans up various things I noticed while auditing the code for usages of `state_`.

Test Plan:
All the unit tests still pass.
Ran with ASAN (and found I had introduced a bug, then fixed it. yay)

Reviewed By: hannesr@fb.com

Subscribers: jsedgwick, net-systems@, fugalh, exa

FB internal diff: D1412038

Tasks: 4618297
folly/wangle/Future-inl.h
folly/wangle/Future.h
folly/wangle/Promise-inl.h
folly/wangle/Promise.h
folly/wangle/detail/State.h
folly/wangle/test/FutureTest.cpp