From a517f31a9fe442ace8a47a9c4242278ff59f8b47 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Tue, 8 Aug 2017 10:12:36 +0100 Subject: [PATCH] Extract store-async code into a separate private function. --- src/kamokan_impl/submit_paste_response.cpp | 23 +++++++++++++--------- src/kamokan_impl/submit_paste_response.hpp | 1 + 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/kamokan_impl/submit_paste_response.cpp b/src/kamokan_impl/submit_paste_response.cpp index 06aa7fe..8eedff0 100644 --- a/src/kamokan_impl/submit_paste_response.cpp +++ b/src/kamokan_impl/submit_paste_response.cpp @@ -191,15 +191,7 @@ namespace kamokan { Storage::SubmissionResult submission_res = storage.submit_pastie(parText, parExpiry, parLang, parSelfDestruct, remote_ip); if (not submission_res.error) { - //if data was submitted successfully, start a separate thread to do - //the syntax highlighting and upload that to the storage asynchronously - //since it's likely to take a long time - assert(not m_local->submit_thread.joinable()); - std::string lang(parLang); - std::string text(parText); - m_local->submit_thread = std::thread([&,text,token=submission_res.token,lang]() mutable { - this->store_highlighted_pastie(token, std::move(text), lang); - }); + store_highlighted_pastie_async(submission_res.token, parText, parLang); return std::make_pair(boost::make_optional(std::move(submission_res.token)), tawashi::HttpHeader()); } @@ -224,6 +216,19 @@ namespace kamokan { } } + void SubmitPasteResponse::store_highlighted_pastie_async (boost::string_view parToken, boost::string_view parText, boost::string_view parLang) { + //if data was submitted successfully, start a separate thread to do + //the syntax highlighting and upload that to the storage asynchronously + //since it's likely to take a long time + assert(not m_local->submit_thread.joinable()); + std::string lang(parLang); + std::string text(parText); + std::string token(parToken); + m_local->submit_thread = std::thread([&,text,token,lang]() mutable { + this->store_highlighted_pastie(token, std::move(text), lang); + }); + } + void SubmitPasteResponse::store_highlighted_pastie (boost::string_view parToken, std::string&& parText, boost::string_view parLang) { if (parLang.empty() or parLang == "colourless") return; diff --git a/src/kamokan_impl/submit_paste_response.hpp b/src/kamokan_impl/submit_paste_response.hpp index 3813e62..844d9dd 100644 --- a/src/kamokan_impl/submit_paste_response.hpp +++ b/src/kamokan_impl/submit_paste_response.hpp @@ -62,6 +62,7 @@ namespace kamokan { const boost::string_view& parLang, bool parSelfDestruct ); + void store_highlighted_pastie_async (boost::string_view parToken, boost::string_view parText, boost::string_view parLang); void store_highlighted_pastie (boost::string_view parToken, std::string&& parText, boost::string_view parLang); std::unique_ptr m_local;