|
StripeKit 0.1.1
Stripe integration toolkit for C++
|
Makes a callback safe to hand to code that might fire it more than once. More...
#include <Callback.h>
Public Types | |
| using | Callback = std::function<void(Args...)> |
| Signature of the wrapped callback. | |
Public Member Functions | |
| OnceCallback (Callback callback) | |
| Wraps a callback. | |
| bool | invoke (Args... args) |
| Calls the wrapped callback, unless it has already been called. | |
| bool | was_invoked () const |
| Reports whether the callback has run. | |
Makes a callback safe to hand to code that might fire it more than once.
StripeKit's callback-form methods must invoke their completion exactly once: calling it twice corrupts whatever is waiting on it, and never calling it hangs the request. Adapters wrap the completion in one of these so the rule holds even on unusual error paths.
Safe to call from several threads at once.
| Args | Argument types the wrapped callback takes. |
Definition at line 40 of file Callback.h.
| using stripekit::OnceCallback< Args >::Callback = std::function<void(Args...)> |
Signature of the wrapped callback.
Definition at line 43 of file Callback.h.
|
inlineexplicit |
Wraps a callback.
| callback | The callback to guard. May be empty, in which case invoke() still reports the first call but does nothing. |
Definition at line 51 of file Callback.h.
|
inline |
Calls the wrapped callback, unless it has already been called.
| args | Arguments forwarded to the callback. |
Definition at line 60 of file Callback.h.
|
inline |
Reports whether the callback has run.
Definition at line 83 of file Callback.h.