diff --git a/include/asynchronousContinuation.h b/include/asynchronousContinuation.h index 5594b59..c93e9d2 100644 --- a/include/asynchronousContinuation.h +++ b/include/asynchronousContinuation.h @@ -33,23 +33,6 @@ public: std::shared_ptr> lifetimePreservingConveyance); - /** - * @brief Call the original callback with perfect forwarding - * - * IMPORTANT: This method cannot be virtual because templates cannot be - * virtual in C++. Therefore, this method MUST be called from the - * most-derived class reference/pointer context. Never call this method - * through a polymorphic base class reference/pointer, as it will not - * dispatch to the correct derived class implementation. - * - * @param args Arguments to forward to the original callback - */ - template - void callOriginalCb(Args&&... args) - { - if (originalCbFn) { originalCbFn(std::forward(args)...); } - } - public: OriginalCbFnT originalCbFn; }; @@ -73,8 +56,24 @@ public: : AsynchronousContinuation(originalCbFn) {} -public: - using AsynchronousContinuation::callOriginalCb; + /** + * @brief Call the original callback with perfect forwarding + * (immediate execution) + * + * This implementation calls the original callback immediately without + * posting to any thread or queue. Used for non-posted continuations. + * + * @param args Arguments to forward to the original callback + */ + template + void callOriginalCb(Args&&... args) + { + if (AsynchronousContinuation::originalCbFn) + { + AsynchronousContinuation::originalCbFn( + std::forward(args)...); + } + } }; template @@ -92,7 +91,8 @@ public: template void callOriginalCb(Args&&... args) { - if (AsynchronousContinuation::originalCbFn) { + if (AsynchronousContinuation::originalCbFn) + { caller->getIoService().post( std::bind( AsynchronousContinuation::originalCbFn, @@ -102,7 +102,6 @@ public: public: std::shared_ptr caller; - using AsynchronousContinuation::callOriginalCb; }; template @@ -125,9 +124,6 @@ public: PostedAsynchronousContinuation::callOriginalCb( std::forward(args)...); } - -public: - using AsynchronousContinuation::callOriginalCb; }; } // namespace smo