GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
fix(infra): fully wrap `Bus` methods in lock statements
Lars Bergerfa3b8f29d271
diff --git a/GlazeWM.Infrastructure/Bussing/Bus.cs b/GlazeWM.Infrastructure/Bussing/Bus.csindex 762c0a37..cb63e916 100644--- a/GlazeWM.Infrastructure/Bussing/Bus.cs+++ b/GlazeWM.Infrastructure/Bussing/Bus.cs@@ -24,16 +24,16 @@ namespace GlazeWM.Infrastructure.Bussing/// </summary>public CommandResponse Invoke<T>(T command) where T : Command{- _logger.LogDebug("Command {commandName} invoked.", command.Name);+ lock (LockObj)+ {+ _logger.LogDebug("Command {commandName} invoked.", command.Name);- // Create a `Type` object representing the constructed `ICommandHandler` generic.- var handlerType = typeof(ICommandHandler<>).MakeGenericType(command.GetType());+ // Create a `Type` object representing the constructed `ICommandHandler` generic.+ var handlerType = typeof(ICommandHandler<>).MakeGenericType(command.GetType());- var handlerInstance = ServiceLocator.GetRequiredService(handlerType)- as ICommandHandler<T>;+ var handlerInstance = ServiceLocator.GetRequiredService(handlerType)+ as ICommandHandler<T>;- lock (LockObj)- {return handlerInstance.Handle(command);}}@@ -48,22 +48,22 @@ namespace GlazeWM.Infrastructure.Bussing/// </summary>public void Emit<T>(T @event) where T : Event{- // Create a `Type` object representing the constructed `IEventHandler` generic.- var handlerType = typeof(IEventHandler<>).MakeGenericType(@event.GetType());+ lock (LockObj)+ {+ // Create a `Type` object representing the constructed `IEventHandler` generic.+ var handlerType = typeof(IEventHandler<>).MakeGenericType(@event.GetType());- var handlerInstances = ServiceLocator.GetServices(handlerType)- as IEnumerable<IEventHandler<T>>;+ var handlerInstances = ServiceLocator.GetServices(handlerType)+ as IEnumerable<IEventHandler<T>>;- foreach (var handler in handlerInstances)- {- lock (LockObj)+ foreach (var handler in handlerInstances){handler.Handle(@event);}- }- // Emit event through subject.- Events.OnNext(@event);+ // Emit event through subject.+ Events.OnNext(@event);+ }}public Task EmitAsync<T>(T @event) where T : Event