web_service: stop using std::future + callback style async

This commit is contained in:
Weiyi Wang
2018-09-12 12:22:48 -04:00
parent 0a4d338ffa
commit 77c1f647cb
23 changed files with 329 additions and 457 deletions

View File

@@ -63,7 +63,8 @@ Lobby::Lobby(QWidget* parent, QStandardItemModel* list,
connect(ui->room_list, &QTreeView::clicked, this, &Lobby::OnExpandRoom);
// Actions
connect(this, &Lobby::LobbyRefreshed, this, &Lobby::OnRefreshLobby);
connect(&room_list_watcher, &QFutureWatcher<AnnounceMultiplayerRoom::RoomList>::finished, this,
&Lobby::OnRefreshLobby);
// manually start a refresh when the window is opening
// TODO(jroweboy): if this refresh is slow for people with bad internet, then don't do it as
@@ -149,16 +150,17 @@ void Lobby::ResetModel() {
void Lobby::RefreshLobby() {
if (auto session = announce_multiplayer_session.lock()) {
ResetModel();
room_list_future = session->GetRoomList([&]() { emit LobbyRefreshed(); });
ui->refresh_list->setEnabled(false);
ui->refresh_list->setText(tr("Refreshing"));
room_list_watcher.setFuture(
QtConcurrent::run([session]() { return session->GetRoomList(); }));
} else {
// TODO(jroweboy): Display an error box about announce couldn't be started
}
}
void Lobby::OnRefreshLobby() {
AnnounceMultiplayerRoom::RoomList new_room_list = room_list_future.get();
AnnounceMultiplayerRoom::RoomList new_room_list = room_list_watcher.result();
for (auto room : new_room_list) {
// find the icon for the game if this person owns that game.
QPixmap smdh_icon;

View File

@@ -4,7 +4,6 @@
#pragma once
#include <future>
#include <memory>
#include <QDialog>
#include <QFutureWatcher>
@@ -61,11 +60,6 @@ private slots:
void OnJoinRoom(const QModelIndex&);
signals:
/**
* Signalled when the latest lobby data is retrieved.
*/
void LobbyRefreshed();
void StateChanged(const Network::RoomMember::State&);
private:
@@ -84,7 +78,7 @@ private:
QStandardItemModel* game_list;
LobbyFilterProxyModel* proxy;
std::future<AnnounceMultiplayerRoom::RoomList> room_list_future;
QFutureWatcher<AnnounceMultiplayerRoom::RoomList> room_list_watcher;
std::weak_ptr<Core::AnnounceMultiplayerSession> announce_multiplayer_session;
std::unique_ptr<Ui::Lobby> ui;
QFutureWatcher<void>* watcher;