[#bsl-stop_callback-06]
= xref:bsl.adoc[bsl]::stop&lowbar;callback
:relfileprefix: ../
:mrdocs:

This class holds an object or reference of type `t&lowbar;CALLBACK` and, when constructed using a `stop&lowbar;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)&period; However, if cancellation was already requested before the `stop&lowbar;callback` was constructed, the constructor invokes the callback immediately&period; If there is no stop state, or `request&lowbar;stop` is never called for the stop state, then the callback is not invoked&period; `stop&lowbar;callback` stores its callback within its own footprint, and thus never requires memory allocation&semi; however, `stop&lowbar;callback&lt;t&lowbar;CALLBACK&gt;` is an allocator&hyphen;aware class, if `t&lowbar;CALLBACK` is an allocator&hyphen;aware class, and any supplied allocator will then be passed to the constructor of `t&lowbar;CALLBACK`&period;

== Synopsis

Declared in `&lt;bslstl&lowbar;stoptoken&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class t&lowbar;CALLBACK&gt;
class stop&lowbar;callback;
----

== Type Aliases

[cols="1,4"]
|===
| Name| Description
| xref:bsl/stop_callback-06/allocator_type.adoc[`allocator&lowbar;type`] 
| The allocator type is `bsl&colon;&colon;allocator&lt;char&gt;` if `t&lowbar;CALLBACK` is allocator&hyphen;aware, and an empty dummy type otherwise&period;
| xref:bsl/stop_callback-06/callback_type.adoc[`callback&lowbar;type`] 
| Alias for the callback callable type stored by this `stop&lowbar;callback`&period;
|===


== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:bsl/stop_callback-06/2constructor-05.adoc[`stop&lowbar;callback`]         [.small]#[constructor]#
| Constructors
| xref:bsl/stop_callback-06/2destructor.adoc[`&#126;stop&lowbar;callback`] [.small]#[destructor]#
| Destroy this object&period; If `&ast;this` refers to a stop state and the stored callback is registered with the stop state but has not yet begun execution, deregister the callback from that stop state&period; Otherwise, if the callback is executing on a thread other than the thread invoking the destructor, the completion of the callback strongly happens before the destructor returns&period;
| xref:bsl/stop_callback-06/get_allocator.adoc[`get&lowbar;allocator`] 
| If `t&lowbar;CALLBACK` is allocator&hyphen;aware, return the allocator used to construct this object&semi; otherwise, the return type is `void` and the definition of this function is ill&hyphen;formed&period;
|===


== Deduction Guides

[cols="1,4"]
|===
| Name| Description
| xref:bsl/stop_callback-01.adoc[`stop&lowbar;callback&lt;t&lowbar;CALLBACK&gt;`] 
| Deduce `t&lowbar;CALLBACK` from the type of the callable passed to `stop&lowbar;callback`&period;
|===



[.small]#Created with https://www.mrdocs.com[MrDocs]#
