reactivity
This commit is contained in:
parent
ced9f72279
commit
a55d71973b
12
DTLib.csproj
12
DTLib.csproj
@ -43,6 +43,7 @@
|
||||
<Compile Include="Dtsod\DtsodV21.cs" />
|
||||
<Compile Include="cs9somefix.cs" />
|
||||
<Compile Include="Dtsod\ValueTypes.cs" />
|
||||
<Compile Include="EventHandlerAsync.cs" />
|
||||
<Compile Include="Filesystem\Directory.cs" />
|
||||
<Compile Include="Filesystem\File.cs" />
|
||||
<Compile Include="Filesystem\OldFilework.cs" />
|
||||
@ -53,12 +54,23 @@
|
||||
<Compile Include="Network\OldNetwork.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Hasher.cs" />
|
||||
<Compile Include="Reactive\ReactiveProvider.cs" />
|
||||
<Compile Include="Reactive\ReactiveStream.cs" />
|
||||
<Compile Include="Reactive\ReactiveListener.cs" />
|
||||
<Compile Include="Reactive\ReactiveWorker.cs" />
|
||||
<Compile Include="SafeMutex.cs" />
|
||||
<Compile Include="SecureRandom.cs" />
|
||||
<Compile Include="SimpleConverter.cs" />
|
||||
<Compile Include="TImer.cs" />
|
||||
<Compile Include="XXHash.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include=".gitignore" />
|
||||
<Content Include="DTLib.sln" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="README.md" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>
|
||||
|
||||
10
EventHandlerAsync.cs
Normal file
10
EventHandlerAsync.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DTLib
|
||||
{
|
||||
public delegate Func<TEventArgs, Task> EventHandlerAsync<TEventArgs>(object sender, TEventArgs e);
|
||||
}
|
||||
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>
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
32
Reactive/ReactiveStream.cs
Normal file
32
Reactive/ReactiveStream.cs
Normal file
@ -0,0 +1,32 @@
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
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));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user