Skip to content

Commit be15a85

Browse files
committed
Added wait function
1 parent 0e94bed commit be15a85

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

source/async_postgres.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ namespace async_postgres {
136136
void process_notifications(GLua::ILuaInterface* lua, Connection* state);
137137

138138
// query.cpp
139+
void process_result(GLua::ILuaInterface* lua, Connection* state,
140+
pg::result&& result);
139141
void process_query(GLua::ILuaInterface* lua, Connection* state);
140142

141143
// result.cpp

source/main.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,33 @@ namespace async_postgres::lua {
200200

201201
return 0;
202202
}
203+
204+
lua_protected_fn(wait) {
205+
lua->CheckType(1, async_postgres::connection_meta);
206+
207+
auto state = lua_connection_state();
208+
if (state->query) {
209+
auto& query = state->query.value();
210+
211+
// if query wasn't sent, send in through process_query
212+
if (!query.sent) {
213+
async_postgres::process_query(lua, state);
214+
}
215+
216+
// while query is the same and it's not done
217+
while (state->query.has_value() &&
218+
&query == &state->query.value()) {
219+
async_postgres::process_result(lua, state,
220+
pg::getResult(state->conn));
221+
}
222+
223+
lua->PushBool(true);
224+
return 1;
225+
}
226+
227+
lua->PushBool(false);
228+
return 1;
229+
}
203230
} // namespace async_postgres::lua
204231

205232
#define register_lua_fn(name) \
@@ -221,6 +248,7 @@ void register_connection_mt(GLua::ILuaInterface* lua) {
221248
register_lua_fn(describePortal);
222249
register_lua_fn(reset);
223250
register_lua_fn(setNotifyCallback);
251+
register_lua_fn(wait);
224252

225253
async_postgres::register_misc_connection_functions(lua);
226254

source/query.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ inline bool poll_query(PGconn* conn, Query& query) {
9292
return true;
9393
}
9494

95-
void process_result(GLua::ILuaInterface* lua, Connection* state,
96-
pg::result&& result) {
95+
void async_postgres::process_result(GLua::ILuaInterface* lua, Connection* state,
96+
pg::result&& result) {
9797
// query is done
9898
if (!result) {
9999
state->query.reset();

0 commit comments

Comments
 (0)