@@ -116,22 +116,29 @@ class task_future : public task_future_base, public std::enable_shared_from_this
116116 }
117117 }
118118
119- static std::shared_ptr<task_future> create (task_state state = task_state::pending) {
120- return std::make_shared<task_future>(private_construct{}, state);
119+ static std::shared_ptr<task_future> create_pending () {
120+ return std::make_shared<task_future>(private_construct{}, task_state::pending);
121+ }
122+ static std::shared_ptr<task_future> create_ready (T&& value) {
123+ return std::make_shared<task_future>(private_construct{}, std::move (value));
124+ }
125+ static std::shared_ptr<task_future> create_exception (std::exception_ptr exception) {
126+ return std::make_shared<task_future>(private_construct{}, exception);
121127 }
122128 template <typename F>
123129 static std::shared_ptr<task_future> create (F&& work) {
124130 DISPATCH_QUEUE_TRY {
125- return std::make_shared<task_future>(private_construct{}, std::move (work ()));
131+ auto value = work ();
132+ return create_ready (std::move (value));
126133 }
127134 DISPATCH_QUEUE_CATCH (...) {
128- return std::make_shared<task_future>(private_construct{}, std::current_exception ());
135+ return create_exception ( std::current_exception ());
129136 }
130137 }
131138
132139 template <typename F>
133140 auto then (F&& f) {
134- auto continuation_future = task_future<function_result<F>>::create ();
141+ auto continuation_future = task_future<function_result<F>>::create_pending ();
135142 std::unique_lock<std::mutex> lock (mutex);
136143 if (state == task_state::pending) {
137144 continuations.push_back ([=]() {
@@ -206,23 +213,29 @@ class task_future<void> : public task_future_base, public std::enable_shared_fro
206213 {
207214 }
208215
209- static std::shared_ptr<task_future> create (task_state state = task_state::pending) {
210- return std::make_shared<task_future>(private_construct{}, state);
216+ static std::shared_ptr<task_future> create_pending () {
217+ return std::make_shared<task_future>(private_construct{}, task_state::pending);
218+ }
219+ static std::shared_ptr<task_future> create_ready () {
220+ return std::make_shared<task_future>(private_construct{}, task_state::ready);
221+ }
222+ static std::shared_ptr<task_future> create_exception (std::exception_ptr exception) {
223+ return std::make_shared<task_future>(private_construct{}, exception);
211224 }
212225 template <typename F>
213226 static std::shared_ptr<task_future> create (F&& work) {
214227 DISPATCH_QUEUE_TRY {
215228 work ();
216- return std::make_shared<task_future>(private_construct{}, task_state::ready );
229+ return create_ready ( );
217230 }
218231 DISPATCH_QUEUE_CATCH (...) {
219- return std::make_shared<task_future>(private_construct{}, std::current_exception ());
232+ return create_exception ( std::current_exception ());
220233 }
221234 }
222235
223236 template <typename F>
224237 auto then (F&& f) {
225- auto continuation_future = task_future<function_result<F>>::create ();
238+ auto continuation_future = task_future<function_result<F>>::create_pending ();
226239 std::unique_lock<std::mutex> lock (mutex);
227240 if (state == task_state::pending) {
228241 continuations.push_back ([=]() {
0 commit comments