[#bsl-stop_callback-06] = xref:bsl.adoc[bsl]::stop_callback :relfileprefix: ../ :mrdocs: Callback invoked when a stop is requested on an associated stop state. == Synopsis Declared in `<bslstl_stoptoken.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class t_CALLBACK> class stop_callback; ---- == Description This class holds an object or reference of type `t_CALLBACK` and, when constructed using a `stop_token` that owns a stop state, schedules the held object or reference to be executed by the thread that requests cancellation on that stop state (if any). However, if cancellation was already requested before the `stop_callback` was constructed, the constructor invokes the callback immediately. If there is no stop state, or `request_stop` is never called for the stop state, then the callback is not invoked. `stop_callback` stores its callback within its own footprint, and thus never requires memory allocation; however, `stop_callback<t_CALLBACK>` is an allocator‐aware class, if `t_CALLBACK` is an allocator‐aware class, and any supplied allocator will then be passed to the constructor of `t_CALLBACK`. == Type Aliases [cols="1,4"] |=== | Name| Description | xref:bsl/stop_callback-06/allocator_type.adoc[`allocator_type`] | The allocator type is `bsl::allocator<char>` if `t_CALLBACK` is allocator‐aware, and an empty dummy type otherwise. | xref:bsl/stop_callback-06/callback_type.adoc[`callback_type`] | Alias for the callback callable type stored by this `stop_callback`. |=== == Member Functions [cols="1,4"] |=== | Name| Description | xref:bsl/stop_callback-06/2constructor-05.adoc[`stop_callback`] [.small]#[constructor]# | Constructors | xref:bsl/stop_callback-06/2destructor.adoc[`~stop_callback`] [.small]#[destructor]# | Destroy this object and deregister the callback if needed. | xref:bsl/stop_callback-06/get_allocator.adoc[`get_allocator`] | Return the allocator used to construct this object, if any. |=== == Deduction Guides [cols="1,4"] |=== | Name| Description | xref:bsl/stop_callback-01.adoc[`stop_callback<t_CALLBACK>`] | Deduce `t_CALLBACK` from the type of the callable passed to `stop_callback`. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#