1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 01:02:55 +08:00

Fix too many tasks in lookupRoom method

This commit is contained in:
Dean Herbert 2023-10-12 18:11:04 +09:00
parent 5f62c225bf
commit a591af2b97
No known key found for this signature in database

View File

@ -448,7 +448,7 @@ namespace osu.Game.Online.Multiplayer
async Task IMultiplayerClient.Invited(int invitedBy, long roomID, string password) async Task IMultiplayerClient.Invited(int invitedBy, long roomID, string password)
{ {
APIUser? apiUser = await userLookupCache.GetUserAsync(invitedBy); APIUser? apiUser = await userLookupCache.GetUserAsync(invitedBy);
Room? apiRoom = await lookupRoom(roomID); Room? apiRoom = await getRoomAsync(roomID);
if (apiUser == null || apiRoom == null) return; if (apiUser == null || apiRoom == null) return;
@ -462,23 +462,19 @@ namespace osu.Game.Online.Multiplayer
} }
} }
); );
}
private Task<Room?> lookupRoom(long id) Task<Room?> getRoomAsync(long id)
{ {
return Task.Run(() => TaskCompletionSource<Room?> taskCompletionSource = new TaskCompletionSource<Room?>();
{
var t = new TaskCompletionSource<Room?>();
var request = new GetRoomRequest(id); var request = new GetRoomRequest(id);
request.Success += room => taskCompletionSource.TrySetResult(room);
request.Success += room => t.TrySetResult(room); request.Failure += _ => taskCompletionSource.TrySetResult(null);
request.Failure += e => t.TrySetResult(null);
API.Queue(request); API.Queue(request);
return t.Task; return taskCompletionSource.Task;
}); }
} }
private void addUserToAPIRoom(MultiplayerRoomUser user) private void addUserToAPIRoom(MultiplayerRoomUser user)