DTLib/Reactive/ReactiveStream.cs
2021-10-03 00:23:01 +03:00

33 lines
818 B
C#

using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.ObjectModel;
using System.Text;
using System.Threading.Tasks;
namespace DTLib.Reactive
{
public class ReactiveStream<T>
{
List<T> Storage = new();
public event EventHandlerAsync<T> ElementAdded;
bool StoreData = false;
SafeMutex StorageAccess = new();
public ReactiveStream() { }
public ReactiveStream(bool storeData) => StoreData = storeData;
public void Add(T elem)
{
if (StoreData) StorageAccess.Execute(() => Storage.Add(elem));
ElementAdded?.Invoke(this, elem);
}
public void Clear()
{
if (StoreData) StorageAccess.Execute(() => Storage.Clear());
}
}
}