1515 * with this program. If not, see <http://www.gnu.org/licenses/>.
1616 */
1717
18- #ifndef AsyncCallbackProcessor_h__
19- #define AsyncCallbackProcessor_h__
18+ #ifndef TRINITYCORE_ASYNC_CALLBACK_PROCESSOR_H
19+ #define TRINITYCORE_ASYNC_CALLBACK_PROCESSOR_H
2020
21- #include " Define.h"
22- #include < algorithm>
21+ #include " AsyncCallbackProcessorFwd.h"
2322#include < vector>
2423
25- // template <class T>
26- // concept AsyncCallback = requires(T t) { { t.InvokeIfReady() } -> std::convertible_to<bool> };
27-
28- template <typename T> // requires AsyncCallback<T>
24+ template <AsyncCallback T>
2925class AsyncCallbackProcessor
3026{
3127public:
@@ -34,8 +30,7 @@ class AsyncCallbackProcessor
3430
3531 T& AddCallback (T&& query)
3632 {
37- _callbacks.emplace_back (std::move (query));
38- return _callbacks.back ();
33+ return _callbacks.emplace_back (std::move (query));
3934 }
4035
4136 void ProcessReadyCallbacks ()
@@ -45,15 +40,23 @@ class AsyncCallbackProcessor
4540
4641 std::vector<T> updateCallbacks{ std::move (_callbacks) };
4742
48- updateCallbacks. erase ( std::remove_if (updateCallbacks. begin (), updateCallbacks. end () , [](T& callback)
43+ std::erase_if (updateCallbacks, [](T& callback)
4944 {
50- return callback. InvokeIfReady ( );
51- }), updateCallbacks. end ()) ;
45+ return InvokeAsyncCallbackIfReady (callback );
46+ });
5247
5348 _callbacks.insert (_callbacks.end (), std::make_move_iterator (updateCallbacks.begin ()), std::make_move_iterator (updateCallbacks.end ()));
5449 }
5550
56- bool HasPendingCallbacks () { return !_callbacks.empty (); }
51+ bool Empty () const
52+ {
53+ return _callbacks.empty ();
54+ }
55+
56+ void CancelAll ()
57+ {
58+ _callbacks.clear ();
59+ }
5760
5861private:
5962 AsyncCallbackProcessor (AsyncCallbackProcessor const &) = delete ;
@@ -62,4 +65,4 @@ class AsyncCallbackProcessor
6265 std::vector<T> _callbacks;
6366};
6467
65- #endif // AsyncCallbackProcessor_h__
68+ #endif // TRINITYCORE_ASYNC_CALLBACK_PROCESSOR_H
0 commit comments