mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 17:52:56 +08:00
Add thread safety to PollingComponent.Poll
implementations
This commit is contained in:
parent
d1158acb82
commit
c44af4853d
@ -33,7 +33,7 @@ namespace osu.Game.Screens.OnlinePlay.Components
|
||||
});
|
||||
}
|
||||
|
||||
private GetRoomsRequest pollReq;
|
||||
private GetRoomsRequest lastPollRequest;
|
||||
|
||||
protected override Task Poll()
|
||||
{
|
||||
@ -45,10 +45,11 @@ namespace osu.Game.Screens.OnlinePlay.Components
|
||||
|
||||
var tcs = new TaskCompletionSource<bool>();
|
||||
|
||||
pollReq?.Cancel();
|
||||
pollReq = new GetRoomsRequest(Filter.Value.Status, Filter.Value.Category);
|
||||
lastPollRequest?.Cancel();
|
||||
|
||||
pollReq.Success += result =>
|
||||
var req = new GetRoomsRequest(Filter.Value.Status, Filter.Value.Category);
|
||||
|
||||
req.Success += result =>
|
||||
{
|
||||
foreach (var existing in RoomManager.Rooms.ToArray())
|
||||
{
|
||||
@ -66,10 +67,11 @@ namespace osu.Game.Screens.OnlinePlay.Components
|
||||
tcs.SetResult(true);
|
||||
};
|
||||
|
||||
pollReq.Failure += _ => tcs.SetResult(false);
|
||||
req.Failure += _ => tcs.SetResult(false);
|
||||
|
||||
API.Queue(pollReq);
|
||||
API.Queue(req);
|
||||
|
||||
lastPollRequest = req;
|
||||
return tcs.Task;
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ namespace osu.Game.Screens.OnlinePlay.Components
|
||||
this.room = room;
|
||||
}
|
||||
|
||||
private GetRoomRequest pollReq;
|
||||
private GetRoomRequest lastPollRequest;
|
||||
|
||||
protected override Task Poll()
|
||||
{
|
||||
@ -30,19 +30,22 @@ namespace osu.Game.Screens.OnlinePlay.Components
|
||||
|
||||
var tcs = new TaskCompletionSource<bool>();
|
||||
|
||||
pollReq?.Cancel();
|
||||
pollReq = new GetRoomRequest(room.RoomID.Value.Value);
|
||||
lastPollRequest?.Cancel();
|
||||
|
||||
pollReq.Success += result =>
|
||||
var req = new GetRoomRequest(room.RoomID.Value.Value);
|
||||
|
||||
req.Success += result =>
|
||||
{
|
||||
result.RemoveExpiredPlaylistItems();
|
||||
RoomManager.AddOrUpdateRoom(result);
|
||||
tcs.SetResult(true);
|
||||
};
|
||||
|
||||
pollReq.Failure += _ => tcs.SetResult(false);
|
||||
req.Failure += _ => tcs.SetResult(false);
|
||||
|
||||
API.Queue(pollReq);
|
||||
API.Queue(req);
|
||||
|
||||
lastPollRequest = req;
|
||||
|
||||
return tcs.Task;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user