diff --git a/jsonapi-generator/src/async-method-wrapper-template.cpp.tmpl b/jsonapi-generator/src/async-method-wrapper-template.cpp.tmpl index 097ff8d8b..81b97265b 100644 --- a/jsonapi-generator/src/async-method-wrapper-template.cpp.tmpl +++ b/jsonapi-generator/src/async-method-wrapper-template.cpp.tmpl @@ -18,8 +18,8 @@ * * *******************************************************************************/ -registerHandler("$%apiPath%$", - [this, $%captureVars%$](const std::shared_ptr session) +registerHandler( "$%apiPath%$", + [this](const std::shared_ptr session) { const std::multimap headers { @@ -29,7 +29,7 @@ registerHandler("$%apiPath%$", session->yield(rb::OK, headers); size_t reqSize = session->get_request()->get_header("Content-Length", 0); - session->fetch( reqSize, [this, $%captureVars%$]( + session->fetch( reqSize, [this]( const std::shared_ptr session, const rb::Bytes& body ) { @@ -74,5 +74,4 @@ $%outputParamsSerialization%$ session->yield(message.str()); $%sessionDelayedClose%$ } ); -}, $%requiresAuth%$); - +}, $%requiresAuth%$ ); diff --git a/jsonapi-generator/src/jsonapi-generator.cpp b/jsonapi-generator/src/jsonapi-generator.cpp index 1a1ed312d..0a6bf3231 100644 --- a/jsonapi-generator/src/jsonapi-generator.cpp +++ b/jsonapi-generator/src/jsonapi-generator.cpp @@ -92,7 +92,7 @@ int main(int argc, char *argv[]) { QDomDocument hDoc; QString hFilePath(it.next()); - QString parseError; int line, column; + QString parseError; int line = -1, column = -1; QFile hFile(hFilePath); if (!hFile.open(QIODevice::ReadOnly) || !hDoc.setContent(&hFile, &parseError, &line, &column)) @@ -320,18 +320,13 @@ int main(int argc, char *argv[]) "\t\t\tRS_SERIAL_PROCESS(retval);\n"; if(hasOutput) outputParamsSerialization += "\t\t}\n"; - QString captureVars; - QString sessionEarlyClose; if(hasSingleCallback) sessionEarlyClose = "session->close();"; QString sessionDelayedClose; if(hasMultiCallback) - { - sessionDelayedClose = "mService.schedule( [session](){session->close();}, std::chrono::seconds(maxWait+120) );"; - captureVars = "this"; - } + sessionDelayedClose = "RsThread::async( [=](){ std::this_thread::sleep_for(std::chrono::seconds(maxWait+120)); mService.schedule( [=](){ auto session = weakSession.lock(); if(session && session->is_open()) session->close(); } ); } );"; QString callbackParamsSerialization; @@ -381,7 +376,6 @@ int main(int argc, char *argv[]) substitutionsMap.insert("apiPath", apiPath); substitutionsMap.insert("sessionEarlyClose", sessionEarlyClose); substitutionsMap.insert("sessionDelayedClose", sessionDelayedClose); - substitutionsMap.insert("captureVars", captureVars); substitutionsMap.insert("callbackName", callbackName); substitutionsMap.insert("callbackParams", callbackParams); substitutionsMap.insert("callbackParamsSerialization", callbackParamsSerialization); diff --git a/jsonapi-generator/src/method-wrapper-template.cpp.tmpl b/jsonapi-generator/src/method-wrapper-template.cpp.tmpl index 473c7df3e..a3927fba9 100644 --- a/jsonapi-generator/src/method-wrapper-template.cpp.tmpl +++ b/jsonapi-generator/src/method-wrapper-template.cpp.tmpl @@ -18,8 +18,8 @@ * * *******************************************************************************/ -registerHandler("$%apiPath%$", - [$%captureVars%$](const std::shared_ptr session) +registerHandler( "$%apiPath%$", + [](const std::shared_ptr session) { size_t reqSize = session->get_request()->get_header("Content-Length", 0); session->fetch( reqSize, []( @@ -46,5 +46,5 @@ $%outputParamsSerialization%$ // return them to the API caller DEFAULT_API_CALL_JSON_RETURN(rb::OK); } ); -}, $%requiresAuth%$); +}, $%requiresAuth%$ );