template <typename Pool, typename Scope>
|
static auto async_mysql_stmt_prepare(service_context<Pool, Scope> &ctx,
|
char *sql_ptr, std::size_t size)
|
-> ::mcs::execution::task<int>
|
{
|
int ret{0};
|
auto *stmt = ctx.key.connect.raw_stmt();
|
|
auto status = ::mysql_stmt_prepare_start(&ret, stmt, sql_ptr, size);
|
auto h = co_await utils::current_coroutine{};
|
auto call_back_impl = [&](int new_status) noexcept {
|
status = new_status;
|
h.resume();
|
};
|
using call_back_impl_type = decltype(call_back_impl);
|
mariadb_poll_callback_object<call_back_impl_type> callback{call_back_impl};
|
|
auto *mysql = ctx.key.connect.data();
|
auto &loop = ctx.key.loop;
|
auto &pool = ctx.pool;
|
auto &counting_scope = ctx.counting_scope;
|
|
while (status != 0)
|
{
|
loop.register_event(::mysql_get_socket(mysql), status, &callback);
|
co_await std::suspend_always{};
|
#if 0
|
//NOTE: get stuck here. resume from a thread different from the thread of mysql_stmt_prepare_start
|
ex::spawn(ex::starts_on(
|
pool.get_scheduler(),
|
ex::just() | ex::then([&]() noexcept {
|
status = ::mysql_stmt_prepare_cont(&ret, stmt, status);
|
h.resume();
|
})),
|
counting_scope.get_token());
|
co_await std::suspend_always{};
|
#else
|
// NOTE: OK。The threads of mysql_stmt_prepare_start and mysql_stmt_prepare_cont are the same.
|
status = ::mysql_stmt_prepare_cont(&ret, stmt, status);
|
#endif
|
}
|
co_return ret;
|
}
|