Created
December 14, 2015 02:06
-
-
Save mntone/a4de0686f8d249b03b2f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Linq; | |
| using System.Reactive.Linq; | |
| using System.Reactive.Subjects; | |
| using System.Threading.Tasks; | |
| namespace RxTest | |
| { | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| Test().GetAwaiter(); | |
| Console.ReadLine(); | |
| } | |
| private static async Task Test() | |
| { | |
| var subject = new Subject<DateTime>(); | |
| var observer = subject.Buffer(TimeSpan.FromSeconds(2)); | |
| var subscriber = observer.Subscribe(d => Console.WriteLine("o Received data:\n{0}", string.Concat(d.Select(x => " - " + x.ToString("HH:mm:ss.fffZ") + '\n')))); | |
| foreach (var i in Enumerable.Range(0, 5)) | |
| { | |
| var dt = DateTime.Now; | |
| subject.OnNext(dt); | |
| Console.WriteLine("o Published {0}", dt.ToString("HH:mm:ss.fffZ")); | |
| await Task.Delay(100); | |
| } | |
| await Task.Delay(3000); | |
| foreach (var i in Enumerable.Range(0, 5)) | |
| { | |
| var dt = DateTime.Now; | |
| subject.OnNext(dt); | |
| Console.WriteLine("o Published {0}", dt.ToString("HH:mm:ss.fffZ")); | |
| } | |
| Console.WriteLine("o subject is completing…"); | |
| subject.OnCompleted(); | |
| Console.WriteLine("o subject is completed."); | |
| Console.WriteLine("o subject is disposing…"); | |
| subject.Dispose(); | |
| Console.WriteLine("o subject is disposed."); | |
| Console.WriteLine("o subscriber is disposing…"); | |
| subscriber.Dispose(); | |
| Console.WriteLine("o subscriber is disposed."); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment