Skip to content

Commit c44a4d5

Browse files
committed
Fix route_params::spawn to use capy::executor::post
1 parent 622d39b commit c44a4d5

2 files changed

Lines changed: 28 additions & 3 deletions

File tree

include/boost/http_proto/server/route_handler.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <boost/http_proto/detail/config.hpp>
1414
#include <boost/http_proto/server/router_types.hpp>
1515
#include <boost/capy/datastore.hpp>
16+
#include <boost/capy/executor.hpp>
1617
#include <boost/capy/task.hpp>
1718
#include <boost/http_proto/request.hpp> // VFALCO forward declare?
1819
#include <boost/http_proto/request_parser.hpp> // VFALCO forward declare?
@@ -81,6 +82,10 @@ struct BOOST_HTTP_PROTO_SYMBOL_VISIBLE
8182
*/
8283
suspender suspend;
8384

85+
/** Executor associated with the session.
86+
*/
87+
capy::executor ex;
88+
8489
/** Destructor
8590
*/
8691
BOOST_HTTP_PROTO_DECL
@@ -176,7 +181,7 @@ struct BOOST_HTTP_PROTO_SYMBOL_VISIBLE
176181
from the route handler.
177182
*/
178183
BOOST_HTTP_PROTO_DECL
179-
virtual auto spawn(
184+
auto spawn(
180185
capy::task<route_result> coro) ->
181186
route_result;
182187

src/server/route_handler.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,30 @@ set_body(std::string s)
5656
auto
5757
route_params::
5858
spawn(
59-
capy::task<route_result>) ->
59+
capy::task<route_result> t) ->
6060
route_result
6161
{
62-
detail::throw_invalid_argument();
62+
return this->suspend(
63+
[ex = this->ex, t = std::move(t)](resumer resume) mutable
64+
{
65+
auto h = t.release();
66+
67+
h.promise().on_done = [resume, h]()
68+
{
69+
auto& r = h.promise().result;
70+
if(r.index() == 2)
71+
{
72+
auto ep = std::get<2>(r);
73+
h.destroy();
74+
std::rethrow_exception(ep);
75+
}
76+
auto rv = std::move(std::get<1>(r));
77+
h.destroy();
78+
resume(rv);
79+
};
80+
81+
ex.post([h]() { h.resume(); });
82+
});
6383
}
6484

6585
#endif

0 commit comments

Comments
 (0)