BeeeOn Gateway  v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
BlockingAsyncWork.h
1 #pragma once
2 
3 #include <Poco/SingletonHolder.h>
4 
5 #include "util/AbstractAsyncWork.h"
6 
7 namespace BeeeOn {
8 
14 template <typename Result = Poco::Void>
15 class BlockingAsyncWork : public AbstractAsyncWork<Result> {
16 public:
17  typedef Poco::SharedPtr<BlockingAsyncWork<Result>> Ptr;
18 
24  bool tryJoin(const Poco::Timespan &) override;
25 
30  void cancel() override;
31 
38  static typename BlockingAsyncWork<Result>::Ptr instance();
39 };
40 
41 template <typename Result>
42 inline bool BlockingAsyncWork<Result>::tryJoin(const Poco::Timespan &)
43 {
44  return true;
45 }
46 
47 template <typename Result>
49 {
50 }
51 
52 template <typename Result>
53 inline typename BlockingAsyncWork<Result>::Ptr BlockingAsyncWork<Result>::instance()
54 {
55  return new BlockingAsyncWork<Result>;
56 }
57 
58 template <>
59 inline BlockingAsyncWork<Poco::Void>::Ptr BlockingAsyncWork<Poco::Void>::instance()
60 {
61  static Poco::SingletonHolder<BlockingAsyncWork::Ptr> holder;
62 
63  auto &work = *holder.get();
64  if (work.isNull())
66 
67  return work;
68 }
69 
70 }
AbstractAsyncWork provides a generic implementation of method result() and a supplementary method set...
Definition: AbstractAsyncWork.h:17
bool tryJoin(const Poco::Timespan &) override
It immediately returns true because there is nothing to wait for. We are already finished when this m...
Definition: BlockingAsyncWork.h:42
BlockingAsyncWork is an adapter of non-asynchronous operations to the AsyncWork interface. It implements a time barrier that just waits until the underlying operation finishes.
Definition: BlockingAsyncWork.h:15
static BlockingAsyncWork< Result >::Ptr instance()
BlockingAsyncWork does not have to be created everytime it is needed because it does not contain any ...
Definition: BlockingAsyncWork.h:53
void cancel() override
Do nothing because the underlying operation is already finished at the time we can call this method...
Definition: BlockingAsyncWork.h:48