Init
This commit is contained in:
1 parent
a73338916a
commit
fbc1cc8d3e
207 files changed
+10327
-2
No files matched your search
@@ -0,0 +1,46 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Code.Infrastructure.EventBus
|
||||
{
|
||||
internal class SubscribersList<TSubscriber> where TSubscriber : class
|
||||
{
|
||||
private bool m_NeedsCleanUp;
|
||||
|
||||
public bool Executing;
|
||||
|
||||
public readonly List<TSubscriber> List = new(); // TODO Weakptr
|
||||
|
||||
public void Add(TSubscriber subscriber)
|
||||
{
|
||||
List.Add(subscriber);
|
||||
}
|
||||
|
||||
public void Remove(TSubscriber subscriber)
|
||||
{
|
||||
if (Executing)
|
||||
{
|
||||
var i = List.IndexOf(subscriber);
|
||||
if (i >= 0)
|
||||
{
|
||||
m_NeedsCleanUp = true;
|
||||
List[i] = null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
List.Remove(subscriber);
|
||||
}
|
||||
}
|
||||
|
||||
public void Cleanup()
|
||||
{
|
||||
if (!m_NeedsCleanUp)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
List.RemoveAll(s => s == null);
|
||||
m_NeedsCleanUp = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user