1
0
Эх сурвалжийг харах

First hello world example.

Bart De Smet 8 жил өмнө
parent
commit
29f21dba4e

+ 4 - 0
AsyncRx.NET/Playground/Playground.csproj

@@ -5,6 +5,10 @@
     <TargetFramework>netcoreapp2.0</TargetFramework>
   </PropertyGroup>
 
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
+    <LangVersion>7.1</LangVersion>
+  </PropertyGroup>
+
   <ItemGroup>
     <ProjectReference Include="..\System.Reactive.Async\System.Reactive.Async.csproj" />
   </ItemGroup>

+ 37 - 2
AsyncRx.NET/Playground/Program.cs

@@ -1,12 +1,47 @@
 using System;
+using System.Reactive.Linq;
+using System.Reactive.Subjects;
+using System.Threading.Tasks;
 
 namespace Playground
 {
     class Program
     {
-        static void Main(string[] args)
+        static void Main()
         {
-            Console.WriteLine("Hello World!");
+            MainAsync().GetAwaiter().GetResult();
+        }
+
+        static async Task MainAsync()
+        {
+            var subject = new SequentialSimpleAsyncSubject<int>();
+
+            var res = subject.Where(x => x % 2 == 0).Select(x => x + 1);
+
+            await res.SubscribeAsync(
+                x =>
+                {
+                    Console.WriteLine(x);
+                    return Task.CompletedTask;
+                },
+                ex =>
+                {
+                    Console.WriteLine("Error: " + ex);
+                    return Task.CompletedTask;
+                },
+                () =>
+                {
+                    Console.WriteLine("Completed");
+                    return Task.CompletedTask;
+                }
+            );
+
+            for (var i = 0; i < 10; i++)
+            {
+                await subject.OnNextAsync(i);
+            }
+
+            await subject.OnCompletedAsync();
         }
     }
 }