mFrame
載入中...
搜尋中...
無符合項目
Future.h
1
8#ifndef MFRAME_858D7963_BBA9_4496_8D4B_B2D77E1330CC
9#define MFRAME_858D7963_BBA9_4496_8D4B_B2D77E1330CC
10
11/* ***************************************************************************************
12 * Include
13 */
14
15//----------------------------------------------------------------------------------------
16
17//----------------------------------------------------------------------------------------
18#include "./../io/CompletionHandler.h"
19#include "./../util/FutureStatus.h"
20
21/* ***************************************************************************************
22 * Namespace
23 */
24namespace ufm::util {
25 template <typename R>
26 struct Future;
27} // namespace ufm::util
28
29/* ***************************************************************************************
30 * Class/struct/Struct/Enum
31 */
32
42template <typename R = int>
44 /* *************************************************************************************
45 * Method
46 */
55 virtual bool get(R& result, int timeout) abstract;
56
63 virtual bool setWait(void) abstract;
64
72 virtual bool waitDone(int timeout) abstract;
73
77 virtual void clear(void) abstract;
78
84 virtual FutureStatus getStatus(void) abstract;
85 /* *************************************************************************************
86 * Method default
87 */
94 inline bool waitDone(void) {
95 return this->waitDone(0);
96 }
97
105 inline bool get(R& result) {
106 return this->get(result, 0);
107 }
108
115 inline bool isDone(void) {
116 ufm::util::FutureStatus status = this->getStatus();
117 return ((status == ufm::util::FutureStatus::DONE_COMPLETED) ||
119 }
120
127 inline bool isCompleted(void) {
129 }
130
137 inline bool isFailed(void) {
139 }
140
147 inline bool isIdle(void) {
148 return (this->getStatus() == ufm::util::FutureStatus::IDLE);
149 }
150
157 inline bool isBusy(void) {
158 return (this->getStatus() == ufm::util::FutureStatus::WAIT);
159 }
160};
161
162/* ***************************************************************************************
163 * End of file
164 */
165
166#endif /* MFRAME_858D7963_BBA9_4496_8D4B_B2D77E1330CC */
Definition Iterable.h:28
FutureStatus
Definition FutureStatus.h:38
@ IDLE
閒置狀態,表示未開始執行
@ DONE_COMPLETED
完成狀態,表示操作已成功完成
@ DONE_FAILED
失敗狀態,表示操作執行失敗
@ WAIT
等待狀態,表示操作正在執行中
[Interface] 非同步操作完成事件處理器模板介面
Definition CompletionHandler.h:42
[Interface] 非同步操作結果介面
Definition Future.h:43
virtual bool get(R &result, int timeout) override
獲取非同步操作的結果
bool waitDone(void)
等待非同步操作完成,無超時限制
Definition Future.h:94
bool isIdle(void)
檢查操作是否處於閒置狀態
Definition Future.h:147
virtual void clear(void) override
清除當前狀態和結果
virtual FutureStatus getStatus(void) override
獲取當前Future的狀態
virtual bool waitDone(int timeout) override
等待非同步操作完成
bool get(R &result)
獲取非同步操作結果,無超時限制
Definition Future.h:105
virtual bool setWait(void) override
設置為等待狀態
bool isFailed(void)
檢查操作是否已失敗
Definition Future.h:137
bool isCompleted(void)
檢查操作是否已成功完成
Definition Future.h:127
bool isBusy(void)
檢查操作是否處於忙碌(等待)狀態
Definition Future.h:157
bool isDone(void)
檢查操作是否已完成(無論成功或失敗)
Definition Future.h:115