1
0
Fork 0
mirror of https://github.com/KingDuckZ/kamokan.git synced 2024-11-23 00:33:44 +00:00

Extract store-async code into a separate private function.

This commit is contained in:
King_DuckZ 2017-08-08 10:12:36 +01:00
parent 3cb89f9b1f
commit a517f31a9f
2 changed files with 15 additions and 9 deletions

View file

@ -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;

View file

@ -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<LocalData> m_local;