In c++11 how would one go about implementing a program that does two expensive (network) calls, of the same type, and then only waits for the result from the quicker one, not waiting and discarding the slower result. std::thread cant be interrupted and does not return a convenient std::future. And std::async that returns a future, can neither be interrupted nor detached.
The two main issues are:
-Notification when the quicker result has arrived.
-Terminating (and cleanup up) of the slower thread.
NoSenseEtAl provided a link to:
http://fpcomplete.com/functional-patterns-in-c/
There Bartosz provides example code of some very generic composable async API’s. I shamelessly stripped it down to only what I needed (and could understand). Just the “Async Or-Combinator”: