reatcivity
This commit is contained in:
13
Reactive/ReactiveListener.cs
Normal file
13
Reactive/ReactiveListener.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DTLib.Reactive
|
||||
{
|
||||
public class ReactiveListener<T> : ReactiveWorker<T>
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
13
Reactive/ReactiveProvider.cs
Normal file
13
Reactive/ReactiveProvider.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DTLib.Reactive
|
||||
{
|
||||
public class ReactiveProvider<T> : ReactiveWorker<T>
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
28
Reactive/ReactiveStream.cs
Normal file
28
Reactive/ReactiveStream.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
18
Reactive/ReactiveWorker.cs
Normal file
18
Reactive/ReactiveWorker.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DTLib.Reactive
|
||||
{
|
||||
public abstract class ReactiveWorker<T>
|
||||
{
|
||||
List<ReactiveStream<T>> Streams = new();
|
||||
|
||||
SafeMutex StreamCollectionAccess = new();
|
||||
|
||||
public void Join(ReactiveStream<T> stream) => StreamCollectionAccess.Execute(()=>Streams.Add(stream));
|
||||
public void Leave(ReactiveStream<T> stream) => StreamCollectionAccess.Execute(() => Streams.Remove(stream));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user