mirror of
https://github.com/ppy/osu
synced 2025-02-27 08:01:45 +00:00
Fix potential doubling of events
This commit is contained in:
parent
a9e4a0ed50
commit
4cc3321d54
@ -302,14 +302,15 @@ namespace osu.Game.Online.Spectator
|
||||
/// <param name="callback">The action to perform when a user begins playing.</param>
|
||||
/// <param name="runOnceImmediately">Whether the action provided in <paramref name="callback"/> should be run once immediately for all users currently playing.</param>
|
||||
public void BindUserBeganPlaying(Action<int, SpectatorState> callback, bool runOnceImmediately = false)
|
||||
{
|
||||
// The lock is taken before the event is subscribed to to prevent doubling of events.
|
||||
lock (userLock)
|
||||
{
|
||||
OnUserBeganPlaying += callback;
|
||||
|
||||
if (!runOnceImmediately)
|
||||
return;
|
||||
|
||||
lock (userLock)
|
||||
{
|
||||
foreach (var (userId, state) in playingUserStates)
|
||||
callback(userId, state);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user