-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replaced AsyncRequest with Future class
- Loading branch information
Showing
10 changed files
with
131 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* (C) 2024 The University of Chicago | ||
* | ||
* See COPYRIGHT in top-level directory. | ||
*/ | ||
#ifndef __ALPHA_FUTURE_HPP | ||
#define __ALPHA_FUTURE_HPP | ||
|
||
#include <alpha/Exception.hpp> | ||
#include <alpha/Result.hpp> | ||
#include <thallium.hpp> | ||
#include <memory> | ||
#include <functional> | ||
|
||
namespace alpha { | ||
|
||
/** | ||
* @brief Future objects are used to keep track of | ||
* on-going asynchronous operations. | ||
*/ | ||
template<typename T, typename Wrapper = T> | ||
class Future { | ||
|
||
public: | ||
|
||
/** | ||
* @brief Copy constructor. | ||
*/ | ||
Future() = default; | ||
|
||
/** | ||
* @brief Copy constructor. | ||
*/ | ||
Future(const Future& other) = default; | ||
|
||
/** | ||
* @brief Move constructor. | ||
*/ | ||
Future(Future&& other) = default; | ||
|
||
/** | ||
* @brief Copy-assignment operator. | ||
*/ | ||
Future& operator=(const Future& other) = default; | ||
|
||
/** | ||
* @brief Move-assignment operator. | ||
*/ | ||
Future& operator=(Future&& other) = default; | ||
|
||
/** | ||
* @brief Destructor. | ||
*/ | ||
~Future() = default; | ||
|
||
/** | ||
* @brief Wait for the request to complete. | ||
*/ | ||
T wait() { | ||
Result<Wrapper> result = m_resp.wait(); | ||
return std::move(result).valueOrThrow(); | ||
} | ||
|
||
/** | ||
* @brief Test if the request has completed, without blocking. | ||
*/ | ||
bool completed() const { | ||
return m_resp.received(); | ||
} | ||
|
||
/** | ||
* @brief Constructor. | ||
*/ | ||
Future(thallium::async_response resp) | ||
: m_resp(std::move(resp)) {} | ||
|
||
private: | ||
|
||
thallium::async_response m_resp; | ||
}; | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.