template <typename Sig>
class CancelableCallback
CancelableCallback is a wrapper around fit::function that allows the
cancellation of a callback. CancelableCallback takes a reference on the
wrapped callback until this object is destroyed or Reset()/Cancel() are
called.
THREAD-SAFETY:
CancelableCallback objects must be created on, posted to, canceled on, and
destroyed on the same thread.
EXAMPLE USAGE:
void MyTimeoutCallback(std::string message) {
FX_LOGS(INFO)
<
<
"Timeout has expired: "
<
<
message
}
CancelableClosure cancelable(
std::bind(
&MyTimeoutCallback
, "Drinks at Foo Bar!"));
my_task_runner->PostDelayedTask(cancelable.callback(),
TimeDelta::FromSeconds(5));
...
cancelable.Cancel(); // Assuming this happens before the 5 seconds expire.