diff --git a/include/AsynchronousContinuation.h b/include/AsynchronousContinuation.h new file mode 100644 index 0000000..c9a2860 --- /dev/null +++ b/include/AsynchronousContinuation.h @@ -0,0 +1,50 @@ +#ifndef ASYNCHRONOUS_CONTINUATION_H +#define ASYNCHRONOUS_CONTINUATION_H + +#include +#include + +/** + * AsynchronousContinuation - Template base class for async sequence management + * + * This template provides a common pattern for managing asynchronous operations + * that need to maintain object lifetime through a sequence of callbacks. + * + * The template parameter OriginalCbFnT represents the signature of the original + * callback that will be invoked when the async sequence completes. + * + * Usage: + * class MyAsyncReq + * : public AsynchronousContinuation> + * { + * public: + * MyAsyncReq(std::function originalCbFn) + * : AsynchronousContinuation(originalCbFn) + * {} + * + * // Segment methods take only the shared_ptr for lifetime management + * void myAsyncReq1(std::shared_ptr context); + * void myAsyncReq2(std::shared_ptr context); + * }; + */ +template +class AsynchronousContinuation +{ +public: + explicit AsynchronousContinuation(OriginalCbFnT originalCbFn) + : originalCbFn(std::move(originalCbFn)) + {} + + /** EXPLANATION: + * Each numbered segmented sequence persists the lifetime of the + * continuation object by taking a copy of its shared_ptr. + */ + typedef void (SegmentFn)( + std::shared_ptr> + lifetimePreservingConveyance); + +protected: + OriginalCbFnT originalCbFn; +}; + +#endif // ASYNCHRONOUS_CONTINUATION_H