mirror of
https://github.com/bitwarden/mobile.git
synced 2024-11-04 08:50:18 +01:00
add locking to BroadcasterService
This commit is contained in:
parent
f6f6253eab
commit
6c88d25941
@ -9,8 +9,11 @@ namespace Bit.App.Services
|
||||
public class BroadcasterService : IBroadcasterService
|
||||
{
|
||||
private readonly Dictionary<string, Action<Message>> _subscribers = new Dictionary<string, Action<Message>>();
|
||||
private object _myLock = new object();
|
||||
|
||||
public void Send(Message message, string id = null)
|
||||
{
|
||||
lock(_myLock)
|
||||
{
|
||||
if(!string.IsNullOrWhiteSpace(id))
|
||||
{
|
||||
@ -25,8 +28,11 @@ namespace Bit.App.Services
|
||||
Task.Run(() => sub.Value.Invoke(message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Subscribe(string id, Action<Message> messageCallback)
|
||||
{
|
||||
lock(_myLock)
|
||||
{
|
||||
if(_subscribers.ContainsKey(id))
|
||||
{
|
||||
@ -34,8 +40,11 @@ namespace Bit.App.Services
|
||||
}
|
||||
_subscribers.Add(id, messageCallback);
|
||||
}
|
||||
}
|
||||
|
||||
public void Unsubscribe(string id)
|
||||
{
|
||||
lock(_myLock)
|
||||
{
|
||||
if(_subscribers.ContainsKey(id))
|
||||
{
|
||||
@ -43,4 +52,5 @@ namespace Bit.App.Services
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user