cancellation_callback and cancellation_observer
cancellation_callback
registers a callback that will be invoked when
cancellation occurs.
cancellation_observer
checks for cancellation, potentially invoking the handler
and returns whether cancellation occured.
Prototype
template <typename F>
struct cancellation_callback {
cancellation_callback(cancellation_token ct, F functor = {}); // (1)
cancellation_callback(const cancellation_callback &) = delete;
cancellation_callback(cancellation_callback &&) = delete;
cancellation_callback &operator=(const cancellation_callback &) = delete;
cancellation_callback &operator=(cancellation_callback &&) = delete;
void unbind(); // (2)
};
template <typename F>
struct cancellation_observer {
cancellation_observer(F functor = {}); // (3)
cancellation_observer(const cancellation_observer &) = delete;
cancellation_observer(cancellation_observer &&) = delete;
cancellation_observer &operator=(const cancellation_observer &) = delete;
cancellation_observer &operator=(cancellation_observer &&) = delete;
bool try_set(cancellation_token ct); // (4)
bool try_reset(); // (5)
};
- Constructs and attaches the cancellation callback to the given token.
- Detaches the cancellation callback.
- Constructs a cancellation observer.
- Attaches the cancellation observer to the given token and checks for cancellation without invoking the functor.
- Checks for cancellation, potentially invoking the functor, and detaches the cancellation observer.
Requirements
F
is a functor that takes no arguments.
Arguments
ct
- the cancellation token to attach to.functor
- the functor to call on cancellation.
Return values
- N/A
- This method doesn't return any value.
- N/A
- Returns
false
if cancellation was already requested and the observer hasn't been attached,true
otherwise. - Same as (4).