reatcivity

This commit is contained in:
Timerix 2021-10-03 00:17:31 +03:00
parent ced9f72279
commit 35cb0bc7b6
6 changed files with 94 additions and 0 deletions

View File

@ -43,6 +43,7 @@
<Compile Include="Dtsod\DtsodV21.cs" /> <Compile Include="Dtsod\DtsodV21.cs" />
<Compile Include="cs9somefix.cs" /> <Compile Include="cs9somefix.cs" />
<Compile Include="Dtsod\ValueTypes.cs" /> <Compile Include="Dtsod\ValueTypes.cs" />
<Compile Include="EventHandlerAsync.cs" />
<Compile Include="Filesystem\Directory.cs" /> <Compile Include="Filesystem\Directory.cs" />
<Compile Include="Filesystem\File.cs" /> <Compile Include="Filesystem\File.cs" />
<Compile Include="Filesystem\OldFilework.cs" /> <Compile Include="Filesystem\OldFilework.cs" />
@ -53,12 +54,23 @@
<Compile Include="Network\OldNetwork.cs" /> <Compile Include="Network\OldNetwork.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Hasher.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="SafeMutex.cs" />
<Compile Include="SecureRandom.cs" /> <Compile Include="SecureRandom.cs" />
<Compile Include="SimpleConverter.cs" /> <Compile Include="SimpleConverter.cs" />
<Compile Include="TImer.cs" /> <Compile Include="TImer.cs" />
<Compile Include="XXHash.cs" /> <Compile Include="XXHash.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Content Include=".gitignore" />
<Content Include="DTLib.sln" />
</ItemGroup>
<ItemGroup>
<None Include="README.md" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup> <PropertyGroup>
<PostBuildEvent> <PostBuildEvent>

10
EventHandlerAsync.cs Normal file
View 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);
}

View 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>
{
}
}

View 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>
{
}
}

View 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);
}
}
}

View 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));
}
}