1#ifndef NEFORCE_CORE_ASYNC_ASYNC_RESULT_HPP__
2#define NEFORCE_CORE_ASYNC_ASYNC_RESULT_HPP__
18#include "NeForce/core/exception/system_exception.hpp"
21NEFORCE_BEGIN_NAMESPACE__
52template <
typename Token,
typename Signature>
59 explicit async_result(Token& t) :
62 handler_type get_handler() {
return move(token_); }
69template <
typename... Args>
70struct future_handler {
71 shared_ptr<promise<tuple<Args...>>> promise_;
73 void operator()(Args... args) { promise_->set_value(
make_tuple(
move(args)...)); }
77struct future_handler<error_code> {
78 shared_ptr<promise<void>> promise_;
80 void operator()(error_code ec) {
84 promise_->set_value();
90struct future_handler<error_code,
size_t> {
91 shared_ptr<promise<size_t>> promise_;
93 void operator()(error_code ec,
size_t n) {
97 promise_->set_value(n);
106struct async_result<use_future_t, void(error_code)> {
107 using handler_type = inner::future_handler<error_code>;
108 using return_type = future<void>;
109 handler_type handler_;
110 explicit async_result(use_future_t ) { handler_.promise_ = make_shared<promise<void>>(); }
111 handler_type get_handler() {
return handler_; }
112 return_type
get() {
return handler_.promise_->get_future(); }
116struct async_result<use_future_t, void(error_code,
size_t)> {
117 using handler_type = inner::future_handler<error_code, size_t>;
118 using return_type = future<size_t>;
119 handler_type handler_;
120 explicit async_result(use_future_t ) { handler_.promise_ = make_shared<promise<size_t>>(); }
121 handler_type get_handler() {
return handler_; }
122 return_type
get() {
return handler_.promise_->get_future(); }
125template <
typename... Args>
126struct async_result<detached_t, void(Args...)> {
127 struct detached_handler {
130 void operator()(Args... args) {
140 using handler_type = detached_handler;
141 using return_type = void;
143 explicit async_result(detached_t ) {}
144 handler_type get_handler() {
145 return detached_handler{[](Args...) {}};
152NEFORCE_END_NAMESPACE__
enable_if_t< is_void_v< T >, future_result_t< T > > get(future< T > &f)
通用future结果获取函数
constexpr deferred_t deferred
deferred 常量
constexpr detached_t detached
detached 常量
constexpr use_future_t use_future
use_future 常量
exception_ptr make_exception_ptr(Ex ex) noexcept
创建异常指针
constexpr Iterator2 move(Iterator1 first, Iterator1 last, Iterator2 result) noexcept(noexcept(inner::__move_aux(first, last, result)))
移动范围元素
constexpr tuple< unwrap_ref_decay_t< Types >... > make_tuple(Types &&... args)
从参数创建元组
function< float(float)> function
缓动函数类型:输入归一化时间 [0,1],输出进度 [0,1]
Token handler_type
handler 类型