Always clear worker after fetching lyrics completed

This commit is contained in:
Andrzej Rybczak
2016-11-21 12:04:46 +01:00
parent 00f70e23e6
commit c422b993db
2 changed files with 13 additions and 4 deletions

View File

@@ -227,9 +227,8 @@ void Lyrics::update()
} }
else else
w << "\nLyrics were not found.\n"; w << "\nLyrics were not found.\n";
clearWorker();
m_refresh_window = true; m_refresh_window = true;
// Reset worker so it's no longer valid.
m_worker = std::future<boost::optional<std::string>>();
} }
} }
@@ -273,7 +272,10 @@ void Lyrics::fetch(const MPD::Song &s)
w.clear(); w.clear();
m_song = s; m_song = s;
if (loadLyrics(w, lyricsFilename(m_song))) if (loadLyrics(w, lyricsFilename(m_song)))
{
clearWorker();
m_refresh_window = true; m_refresh_window = true;
}
else else
{ {
m_shared_buffer = std::make_shared<Shared<NC::Buffer>>(); m_shared_buffer = std::make_shared<Shared<NC::Buffer>>();
@@ -295,8 +297,7 @@ void Lyrics::refetchCurrent()
} }
else else
{ {
// Get rid of current worker so fetch can restart the process. clearWorker();
m_worker = std::future<boost::optional<std::string>>();
fetch(m_song); fetch(m_song);
} }
} }
@@ -417,3 +418,9 @@ boost::optional<std::string> Lyrics::tryTakeConsumerMessage()
} }
return result; return result;
} }
void Lyrics::clearWorker()
{
m_shared_buffer.reset();
m_worker = std::future<boost::optional<std::string>>();
}

View File

@@ -88,6 +88,8 @@ private:
boost::optional<std::string> message; boost::optional<std::string> message;
}; };
void clearWorker();
bool m_refresh_window; bool m_refresh_window;
size_t m_scroll_begin; size_t m_scroll_begin;