react subjects
This commit is contained in:
parent
61c29e901f
commit
88519cab08
|
@ -35,19 +35,36 @@
|
|||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Reactive, Version=4.1.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Reactive.4.1.5\lib\net46\System.Reactive.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.2\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Windows" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="WindowsBase" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SampleEventArgs.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
|
@ -1,7 +1,10 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Reactive.Subjects;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConsoleAppReact
|
||||
|
@ -10,6 +13,57 @@ namespace ConsoleAppReact
|
|||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
/*
|
||||
var calc = new Calc();
|
||||
calc.Subject.Subscribe((i) => { Console.WriteLine("RX: " + i); });
|
||||
calc.Subject.Throttle(TimeSpan.FromSeconds(10)).Subscribe((i) => { Console.WriteLine("RX (Throttle): " + i); });
|
||||
calc.add(1, 5);
|
||||
*/
|
||||
|
||||
var d = new DoIt();
|
||||
|
||||
/*
|
||||
d.DoIt2(1,2).Subscribe((i) =>
|
||||
{ Console.WriteLine("RX (doit2): " + i); });
|
||||
*/
|
||||
|
||||
d.DoIt2(1, 2).Sample(TimeSpan.Zero).Subscribe((i) =>
|
||||
{ Console.WriteLine("RX (doit2, Sample): " + i); });
|
||||
|
||||
Console.Read();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class DoIt
|
||||
{
|
||||
|
||||
public IObservable<int> DoIt2(int i1, int i2)
|
||||
{
|
||||
var calc = new Calc();
|
||||
calc.add(1, 5);
|
||||
|
||||
return calc.Subject;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class Calc
|
||||
{
|
||||
//public Subject<int> Subject = new Subject<int>();
|
||||
|
||||
public ReplaySubject<int> Subject = new ReplaySubject<int>();
|
||||
|
||||
public void add(int i1, int i2)
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
res += i1 + i2;
|
||||
Subject.OnNext(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
namespace ConsoleAppReact
|
||||
{
|
||||
public class SampleEventArgs
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="System.Reactive" version="4.1.5" targetFramework="net472" />
|
||||
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.2" targetFramework="net472" />
|
||||
<package id="System.Threading.Tasks.Extensions" version="4.5.2" targetFramework="net472" />
|
||||
<package id="System.ValueTuple" version="4.5.0" targetFramework="net472" />
|
||||
</packages>
|
Loading…
Reference in New Issue