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
309template <typename R = int>
311 /* *************************************************************************************
312 * Method
313 */
321 virtual bool get(R& result, int timeout) abstract;
322
328 virtual bool setWait(void) abstract;
329
336 virtual bool waitDone(int timeout) abstract;
337
341 virtual void clear(void) abstract;
342
348 virtual FutureStatus getStatus(void) abstract;
349 /* *************************************************************************************
350 * Method default
351 */
358 inline bool waitDone(void) {
359 return this->waitDone(0);
360 }
361
369 inline bool get(R& result) {
370 return this->get(result, 0);
371 }
372
379 inline bool isDone(void) {
380 ufm::util::FutureStatus status = this->getStatus();
381 return ((status == ufm::util::FutureStatus::DONE_COMPLETED) ||
383 }
384
391 inline bool isCompleted(void) {
393 }
394
401 inline bool isFailed(void) {
403 }
404
411 inline bool isIdle(void) {
412 return (this->getStatus() == ufm::util::FutureStatus::IDLE);
413 }
414
421 inline bool isBusy(void) {
422 return (this->getStatus() == ufm::util::FutureStatus::WAIT);
423 }
424};
425
426/* ***************************************************************************************
427 * End of file
428 */
429
430#endif /* MFRAME_858D7963_BBA9_4496_8D4B_B2D77E1330CC */
Definition Iterable.h:28
FutureStatus
異步操作狀態列舉,定義 Future 物件的所有可能狀態。
Definition FutureStatus.h:239
@ IDLE
閒置狀態,操作尚未開始或已被重設
@ DONE_COMPLETED
成功完成狀態,操作已成功完成並可獲取結果
@ DONE_FAILED
失敗狀態,操作執行過程中發生錯誤
@ WAIT
等待狀態,操作正在執行中
[Interface] 非同步操作完成事件處理器模板介面
Definition CompletionHandler.h:42
非同步操作結果介面,提供異步任務的監控和結果獲取功能。
Definition Future.h:310
virtual bool get(R &result, int timeout) override
獲取非同步操作的結果
bool waitDone(void)
等待非同步操作完成,無超時限制
Definition Future.h:358
bool isIdle(void)
檢查操作是否處於閒置狀態
Definition Future.h:411
virtual void clear(void) override
清除當前狀態和結果
virtual FutureStatus getStatus(void) override
獲取當前 Future 的狀態
virtual bool waitDone(int timeout) override
等待非同步操作完成
bool get(R &result)
獲取非同步操作結果,無超時限制
Definition Future.h:369
virtual bool setWait(void) override
設定為等待狀態
bool isFailed(void)
檢查操作是否已失敗
Definition Future.h:401
bool isCompleted(void)
檢查操作是否已成功完成
Definition Future.h:391
bool isBusy(void)
檢查操作是否處於忙碌(等待)狀態
Definition Future.h:421
bool isDone(void)
檢查操作是否已完成(無論成功或失敗)
Definition Future.h:379