6 #include <Poco/Event.h>
7 #include <Poco/Logger.h>
8 #include <Poco/RunnableAdapter.h>
9 #include <Poco/Thread.h>
11 #include "util/AbstractAsyncWork.h"
12 #include "util/Joiner.h"
13 #include "util/Loggable.h"
14 #include "util/ThreadNamer.h"
23 template <
typename Result = Poco::Vo
id>
26 typedef Poco::SharedPtr<DelayedAsyncWork<Result>> Ptr;
27 typedef std::function<void(DelayedAsyncWork<Result> &)> Call;
31 const Poco::Timespan &delay);
35 const Poco::Timespan &delay);
37 bool tryJoin(
const Poco::Timespan &timeout)
override;
46 Poco::Timespan m_delay;
48 Poco::RunnableAdapter<DelayedAsyncWork> m_runnable;
49 Poco::Thread m_thread;
53 template <
typename Result>
56 const Poco::Timespan &delay):
61 template <
typename Result>
62 DelayedAsyncWork<Result>::DelayedAsyncWork(
65 const Poco::Timespan &delay):
67 m_cancelled(cancelled),
69 m_runnable(*this, &DelayedAsyncWork<Result>::run),
72 m_thread.start(m_runnable);
75 template <
typename Result>
78 return m_finished.tryJoin(timeout);
81 template <
typename Result>
88 template <
typename Result>
91 ThreadNamer namer(
"delayed-by-" + std::to_string(m_delay.totalMilliseconds()));
93 if (m_event.tryWait(m_delay.totalMilliseconds())) {
101 BEEEON_CATCH_CHAIN(logger())
void cancel() override
Cancel the operation this object represents. It should exit immediatelly or at least as soon as possi...
Definition: DelayedAsyncWork.h:82
Implementation of the AsyncWork interface that executes a given function once after the the given del...
Definition: DelayedAsyncWork.h:24
AbstractAsyncWork provides a generic implementation of method result() and a supplementary method set...
Definition: AbstractAsyncWork.h:17
Name the current thread. The name can be assigned permanently or just until the destructor is called...
Definition: ThreadNamer.h:11
Joiner implements join() on a thread that can be called multiple times from different threads...
Definition: Joiner.h:21
bool tryJoin(const Poco::Timespan &timeout) override
Definition: DelayedAsyncWork.h:76
Definition: Loggable.h:19